How to ignore lines in file via rmmissing?

5 ビュー (過去 30 日間)
Ivan Mich
Ivan Mich 2021 年 6 月 8 日
回答済み: Walter Roberson 2021 年 6 月 9 日
Hello
I have a question about a code. I have an xlsx file that icludes three columns. The 3rd column has numbers and some NAN values. I use rmmissing command in order to igner them But I see that the other two columns are not be ignored from my code too. I would like to ignore the lines in which the 3rd column includes NaN values
How could I make it?
My code is
filename1= 'TEST.xlsx' %arxeio me makroseismika
[d1,tex]= importdata(filename1);
A=d1(:,1);
B=d1(:,2);
C=d1(:,7);
C=rmmissing(C)

回答 (2 件)

dpb
dpb 2021 年 6 月 8 日
編集済み: dpb 2021 年 6 月 8 日
Don't create sequentially-named variables, use the array MATLAB so conveniently provided you...
filename1= 'TEST.xlsx' %arxeio me makroseismika
[data,tex]= importdata(filename1);
ix=ismissing(data(:,7)); % find those want to eliminate
data=data(~ix,:); % keep those that aren't missing
tex=tex(~ix,:);
If you do have disparate data types in the file, I strongly suggest to use readtable instead....it handles such in one object instead of having to have two.
  2 件のコメント
Ivan Mich
Ivan Mich 2021 年 6 月 8 日
I am afraid that it is no use
command window shows me :
The logical indices in position 1 contain a true value outside of the array bounds.
dpb
dpb 2021 年 6 月 8 日
編集済み: dpb 2021 年 6 月 8 日
I'm afraid that without any other data to use, it follows precisely the code variables you have in your code snippet...if you expect exact solutions, must supply enough information that is a possible task...
That's the problem with importdata bringing in two disparate variables -- they're not necessarily the same size as apparently is the case here. Nothing can do about that without the information.
As said, use readtable instead.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2021 年 6 月 9 日
A = d1(:,1);
B = d1(:,2);
C = d1(:,7);
mask = ismissing(C);
A(mask) = [];
B(mask) = [];
C(mask) = [];

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by