I need to remove the NaN lines from my output matrix.
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a m file that is meant to read a text file and and convert the data within into a matrix. The issue is that the data has labels scattered through out and I need to remove these labels. So my code currently looks something like:
fid = fopen('Test_Data_2.xyz', 'rt');
datacell = textscan(fid, '%*s %f %f %f', 'HeaderLines', 2, 'CollectOutput', 1);
fclose(fid);
celldisp(datacell)
I then go on to use the data in the outputted matrix. The "celldisp" function currently gives me an output of;
datacell{1} =
3.0697 1.4511 9.8552
1.8283 2.1200 9.3934
1.7869 3.5402 9.8658
0.5861 4.3056 9.3636
NaN NaN NaN
NaN NaN NaN
3.0705 1.4535 9.8578
1.8297 2.1194 9.3960
1.7861 3.5392 9.8658
0.5880 4.3057 9.3634
Where the original data in my text file reads:
46
text-Cs
C 3.069663 1.451149 9.855179
C 1.828334 2.119961 9.393412
C 1.786922 3.540219 9.865837
46
text-Cs
C 3.070549 1.453499 9.857827
C 1.829730 2.119381 9.396008
C 1.786074 3.539174 9.865825
C 0.587989 4.305654 9.363402
Is there any way I can remove the NaN from my output matrix?
댓글 수: 0
채택된 답변
Walter Roberson
2013년 6월 10일
datacell{1}( all(isnan(datacell{1}),2) ) = [];
If you want it to change it so that rows with at least one nan (instead of all nan) are removed, change the "all" to "any"
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!