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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Ive J
Ive J el 10 de En. de 2021
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, :);

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by