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!