Plotting a Text File

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

 采纳的回答

Adam
Adam 2015-4-21
编辑:Adam 2015-4-21
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 个评论

Thanks Adam, I have managed to convert to an ordinary format. How do I now break the data up and plot e.g. 10 plots in this case (but this number can be variable)
OK, Ive done it I think
M=cell2mat(C2)
l=numel(M)
N=reshape(M,[],11)
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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by