How to prevent readtable excluding rows with "NA"?
2 ビュー (過去 30 日間)
古いコメントを表示
I have a textfile in this format (also attached) produced from an image processing loop, which when read in using readtable(), gives me the resulting table.
% Image X Y Area Circularity Extent Height Width
% IMG_0560.jpg NA NA NA NA NA NA NA
% IMG_0561.jpg NA NA NA NA NA NA NA
% IMG_0562.jpg NA NA NA NA NA NA NA
% IMG_0565.jpg 2388.9432 1028.7865 740 1.0291 0.83053 2736 3648
% IMG_0566.jpg 3020.4438 1152.3859 1433 0.99398 0.7788 2736 3648
% IMG_0567.jpg NA NA NA NA NA NA NA
% IMG_0568.jpg 3512.2915 878.88912 1434 1.0338 0.83275 2736 3648
readtable("C:\Desktop\exampletxt.txt");
% Image X Y Area Circularity Extent Height Width
% ________________ ______ ______ ____ ___________ _______ ______ _____
%
% {'IMG_0565.jpg'} 2388.9 1028.8 740 1.0291 0.83053 2736 3648
% {'IMG_0566.jpg'} 3020.4 1152.4 1433 0.99398 0.7788 2736 3648
% {'IMG_0567.jpg'} NaN NaN NaN NaN NaN NaN NaN
% {'IMG_0568.jpg'} 3512.3 878.89 1434 1.0338 0.83275 2736 3648
As you can see it excludes the first few rows that contain NAs, which I need to be included, as it has done correctly for the third row. Is there a way to do this with readtable? Ultimately, all I need is the first column, as I'm then using contain() to see if a given image name exists in this textfile.
0 件のコメント
採用された回答
Star Strider
2021 年 5 月 25 日
Try this —
C1 = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/629630/exampletxt.txt');
VN = C1(1,:);
C1a = C1(2:end,:);
NAI = strcmp(C1(2:end,:), 'NA');
C1a(NAI) = {'NaN'};
T1 = cell2table(C1a, 'VariableNames',VN)
.
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!