Plotting a Text File

2 visualizaciones (últimos 30 días)
Jason
Jason el 21 de Abr. de 2015
Editada: Adam el 21 de Abr. de 2015
I have a text file that has the following format:
The number of actual data points (numbers) could change, and the number of monte carlo runs will also change. How do I read in just the data so I can plot the result each monte carlo run. My real file has 10 monte carlo runs, but as i say it could vary.
#This: Nominal
14.65237
4.80927
0.71514
-1.35440
-1.81233
0.00000
1.81233
1.35440
-0.71514
-4.80927
-14.65237
#This: Monte Carlo File 1
18.33824
8.40410
4.29287
2.21007
1.82274
3.68949
5.60809
5.30485
3.25214
-0.81918
-10.60571
#This: Monte Carlo File 2
14.26151
3.24402
-0.82643
-2.87751
-3.25818
-1.38665
0.52075
0.20150
-1.88288
-5.99502
-15.82859

Respuesta aceptada

Adam
Adam el 21 de Abr. de 2015
Editada: Adam el 21 de Abr. de 2015
Normally I would suggest the following...(or similar)
C = textscan( fid, '%s', 'delimiter', '\n' );
C2 = cellfun( @(x) str2num( x ), C{1} );
but your text file appears to be in UCS-2 little-endian format which causes problems for this. Specifiying little-endian on file opening is simple enough, but UCS-2 is not one of the supported character encodings and my knowledge in that area is pretty much zero.
If you can convert your text file to some more 'ordinary' format then the above should work.
  3 comentarios
Jason
Jason el 21 de Abr. de 2015
OK, Ive done it I think
M=cell2mat(C2)
l=numel(M)
N=reshape(M,[],11)
Adam
Adam el 21 de Abr. de 2015
Editada: Adam el 21 de Abr. de 2015
Ah yes, I forgot that bit because my solution didn't work for me on the text file you had.
You should get an array of your values delimited by NaNs where you had your headings so you can just use those NaNs to break up your result array into plotting blocks.
isnan(C2);
will give you the indices of the NaN values (or ~isnan(C2) the indices of your actual values if that is more useful).
From this it should be quite simple to extract the data.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by