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

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by