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

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

 Accepted Answer

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, :);

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!