Could anyone help me how to extract different specific number of rows in a matrix.

1 回表示 (過去 30 日間)
jaah navi
jaah navi 2021 年 6 月 25 日
コメント済み: Walter Roberson 2021 年 6 月 25 日
I am a matrix of size A= rand(100,1)
I want to generate matrix by extracting 2 rows in interval of 5.
B=A([1:2,6:7,11:12,16:17,........,96:97],:).
Could anyone help me to write in the simplified form to execute in matlab.

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 6 月 25 日
row_idx = reshape((1:5:100) + [0;1],1,[])
row_idx = 1×40
1 2 6 7 11 12 16 17 21 22 26 27 31 32 36 37 41 42 46 47 51 52 56 57 61 62 66 67 71 72
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 6 月 25 日
?? row_idx is already a separate matrix. You take it and
B = A(row_idx,:);
Walter Roberson
Walter Roberson 2021 年 6 月 25 日
For 2, 3, 4 of each group of 5,
row_idx = reshape((1:5:100) + [1;2;3],1,[])

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


Scott MacKenzie
Scott MacKenzie 2021 年 6 月 25 日
B = A(sort([1:5:100 2:5:100]))
  2 件のコメント
jaah navi
jaah navi 2021 年 6 月 25 日
Thanks for your help.
jaah navi
jaah navi 2021 年 6 月 25 日
If suppose instead of two rows I need to have value of 2,3,4 in each intervals of 5. In that case the above command doesnt executes. could you help me on this.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by