comparing table values using isequal
111 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a table M. The second column contains either the letter 's' or letter 'f'.
I would like to put all the rows with the letter 'f' in the second column into a new table A with the following code
pocet_radku = height(M);
j=1;
for i=1:pocet_radku
TF = isequal ("M(i,2)",'f')
if TF == 1
A(j,:)= M(i,:);
j = j+1;
else
end
end
Unfortunatelly, the isequal function return only zeros. Any idea why? In there syntax error that I'm not aware of?
Testing in a command window:
>> isequal ("M(180,2)",'f')
ans =
logical
0
>> M(180,2)
ans =
table
Var2
_____
{'f'}
Thanks a lot for any answers
0 件のコメント
採用された回答
Cris LaPierre
2020 年 9 月 15 日
編集済み: Cris LaPierre
2020 年 9 月 15 日
This can be done much simpler. Try something like this.
A = M(M{:,2}=="f",:);
2 件のコメント
Cris LaPierre
2020 年 9 月 15 日
This can be made even simpler by using the variable name:
A = M(M.Var2=="f",:);
その他の回答 (2 件)
BOB MATHEW SYJI
2020 年 9 月 15 日
Instead of
TF = isequal ("M(i,2)",'f')
try,
TF = strcmp (M.2nd_variable,'f')
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!