How to collect individual bunches of data in a column of a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Darren Nutting
el 15 de Ag. de 2019
Comentada: Darren Nutting
el 19 de Ag. de 2019
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 comentario
Respuesta aceptada
Guillaume
el 15 de Ag. de 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 comentarios
Guillaume
el 19 de Ag. de 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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!