How can I extract multiple rows from an array at regular intervals?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
mcb001
am 11 Aug. 2023
Verschoben: Adam Danz
am 11 Aug. 2023
If I have a simple 72x10 array, how can I make a new array that is made up of the first 6 rows, then miss the next 6, then take the next 6 etc. to the end.
If the main array was A, I know B = A(1:6:end,:)would extract me every 6th row for example, but I want to take a 6-row selection of rows. Output B should be 36x10 (i.e. halved in row length)
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 11 Aug. 2023
Create demo matrix A
A = (1:72)'.*ones(1,10)
size(A)
Extract rows 1:6, 13:18, ...
q = 6;
idxMat = reshape(1:q*floor(height(A)/q),q,[]);
idx = idxMat(:,[1:2:end]);
B = A(idx,:)
size(B)
0 Kommentare
Weitere Antworten (1)
Bruno Luong
am 11 Aug. 2023
Verschoben: Adam Danz
am 11 Aug. 2023
No need for reshape and repmat, etc...
A = reshape(1:720, 72, 10);
B = A((0:12:66) + (1:6)', :) % 66 is size(A,1)-6
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!