行列から条件を指定して値を取り出す
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Masa
el 12 de Nov. de 2020
Comentada: Masa
el 12 de Nov. de 2020
以下のような行列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 comentarios
Respuesta aceptada
Akira Agata
el 12 de Nov. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!