Plotting a Text File
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
Adam
2015-4-21
编辑:Adam
2015-4-21
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!