how to select multiple rows from a large matrix and leave 1 row every time

1 回表示 (過去 30 日間)
Ankita Jindal
Ankita Jindal 2021 年 1 月 10 日
コメント済み: Ankita Jindal 2021 年 1 月 10 日
Hello friends,
Let's say we have a=[20,100];
what I want is to select three rows and leave 4th row then again select 3 rows from 5 to 7 then leave 8th likewise.
selected_rows= ([1:3, 5:7, 9:11, 13:15, 17:19],:) ;
selected_rows=[1 2 3 5 6 7 9 10 11 13 14 15 17 18 19]
but i dont know how to do it automatically I need to use for loop or is there any direct way to do this???
This is very basic question. But still I think may be I will write a long code for doing this.
Can you please suggest me any other way??
Thanks

採用された回答

Ive J
Ive J 2021 年 1 月 10 日
A = rand(20, 100);
keepRowsIdx = setdiff(1:size(A, 1), 4:4:size(A, 1));
Columns 1 through 10
1 2 3 5 6 7 9 10 11 13
Columns 11 through 15
14 15 17 18 19
newA = A(keepRowsIdx, :);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by