Find row(s) of 3x3 matrix where the 1st and 2nd column equals a value
4 ビュー (過去 30 日間)
古いコメントを表示
Sebastian Daneli
2020 年 4 月 27 日
コメント済み: Sebastian Daneli
2020 年 4 月 27 日
Hi
I have a 3x3 matrix, and i would like to find the rows where the 1st and 2nd columns equals a value.
M=[1 2 3
1 1 3
2 1 3]
Lets say I would like to find the row where both the 1st and 2nd column equals 1. In this case i would like to find row 2, and be able to extract the values of that row, i.e. 1 1 3.
0 件のコメント
採用された回答
Sriram Tadavarty
2020 年 4 月 27 日
編集済み: Sriram Tadavarty
2020 年 4 月 27 日
Hi,
Try this:
out = M(M(:,1)==1 & M(:,2)==1,:); % For the example provided with value 1
% For any generic value
out = M(M(:,1)== M(:,2),:);
Hope this helps.
Regards,
Sriram
その他の回答 (1 件)
Ameer Hamza
2020 年 4 月 27 日
編集済み: Ameer Hamza
2020 年 4 月 27 日
M = [1 2 3
1 1 3
2 1 3];
idx = M(:,1)==M(:,2);
M_new = M(idx,:);
Result:
>> M_new
M_new =
1 1 3
参考
カテゴリ
Help Center および File Exchange で Surfaces, Volumes, and Polygons についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!