shift a block of rows to the end of a matrix

4 ビュー (過去 30 日間)
LH
LH 2022 年 11 月 22 日
コメント済み: LH 2022 年 11 月 22 日
Hi,
Suppose I have a matrix:
A = [0 0.2000;
0 0.1578;
0 0.0721;
0 0;
0 0;
0.2000 0;
0.3993 0;
0.4000 0;
0.5428 0;
0.6000 0];
and I need to shift all rows from the beginning until the first ( 0 0) to be put at the end of the matrix so it looks as:
A = [0 0;
0.2000 0;
0.3993 0;
0.4000 0;
0.5428 0;
0.6000 0;
0 0.2000;
0 0.1578;
0 0.0721;
0 0];
I understand that circshift could work, but a generic algorithm of how to do such a shift would be helpful for any matrix A of such form.
Any help would be appreicted.

採用された回答

Stephen23
Stephen23 2022 年 11 月 22 日
A = [0,0.2;0,0.1578;0,0.0721;0,0;0,0;0.2,0;0.3993,0;0.4,0;0.5428,0;0.6,0]
A = 10×2
0 0.2000 0 0.1578 0 0.0721 0 0 0 0 0.2000 0 0.3993 0 0.4000 0 0.5428 0 0.6000 0
N = find(all(A==0,2),1,'first');
B = circshift(A,-N,1)
B = 10×2
0 0 0.2000 0 0.3993 0 0.4000 0 0.5428 0 0.6000 0 0 0.2000 0 0.1578 0 0.0721 0 0
  1 件のコメント
LH
LH 2022 年 11 月 22 日
Brilliant! Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by