How to collect individual bunches of data in a column of a matrix

1 visualizzazione (ultimi 30 giorni)
Hi,
I have a matrix where I would like to collect the first 203 rows of a column into a variable, say e1, then skip the next 813 rows, then collect and add the next 203 rows into e1 again, then skip the next 813 rows... and so on until the end of the column.
I am new to MatLab and could not figure this out myself. Could someone suggest how to do this please?
Thanks
  1 Commento
Adam
Adam il 15 Ago 2019
Modificato: Adam il 15 Ago 2019
idx = repmat( [ones(203,1); zeros(813,1)], n, 1 );
newColumn = oldcolumn( idx );
Something like that would work, where n is however many times you need to repeat the sequence, such that it still fits within oldColumn.

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 15 Ago 2019
Assuming that the length of your column vector is a multiple of 203+813 (if not, what should be done for the last bit that is too short?), then a possible way is to reshape your vector into columns of 203+813 elements and only keep the first 203 rows before reshaping back into a column:
desired = reshape(yourcolumnvector, 203+813, []);
desired = reshape(desired(1:203, :), [], 1)
Another is to simply build the whole list of indices:
indices = (1:203)' + (0:numel(yourcolumnvector)/(203+813)-1) * (203+813);
desired = yourcolumnvector(indices)
  3 Commenti
Guillaume
Guillaume il 19 Ago 2019
My data is not divisible by 203+813
Then what should be done for the last bit of data? If mod(numel(yourvector), 203+813) is >= 203, then it means that you don't have enough skip element, which I guess is not too much of a problem, but if it's < 203, then you don't have enough elements to put in your last column.
The second method simply creates a column vector of indices 1:203, and a row vector of skip 0:(203+813):end. Adding the two together gives you a 2D matrix of indices to extract (because of implicit expansion).
Darren Nutting
Darren Nutting il 19 Ago 2019
Thanks :) And I have managed to use your second method to get it to work now :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by