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!