行列から条件を指定して値を取り出す
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
以下のような行列Aの2行目の要素が0から1に変わった直後の1行目の値を抽出して別の行列として定義したいのですがうまく表現できません.。
次のような行列Aがあるとします.
A=
1 2 3 4 5 6 7
0 1 1 0 1 1 0
このとき,2行目の要素が2行目の要素が0から1に変わった直後の1行目の値を抜き出し,以下のような行列Bとしたいです.
B=
2 5
どのようにすればよいか教えていただけると幸いです。
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 12 Nov. 2020
以下のような方法はいかがでしょうか?
A = [1 2 3 4 5 6 7; 0 1 1 0 1 1 0];
idx = [0 diff(A(2,:))] == 1;
B = A(1,idx);
結果:
>> B
B =
2 5
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!