行列から条件を指定して値を取り出す
Show older comments
以下のような行列Aの1列目の要素が"3"である行を抽出して別の行列として定義したいのですがうまく表現できません.
次のような行列Aがあるとします.
A=
1 -66
2 -61
3 -65
3 -64
1 -66
このとき,1列目の要素が"3"である行を抜き出し,以下のような行列Bとしたいです.
B=
3 -65
3 -64
----------------------------------------------------------------------------------------------------------------------
%Aの1行目が3である行を抽出しBとする
A=[1 -66 ; 2 -61 ; 3 -65 ; 3 -64 ; 1 -66];
B=A[A[:,1].==3,:]
Accepted Answer
More Answers (0)
Categories
Find more on 行列および配列 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!