Borrar filtros
Borrar filtros

Loop to Organize Matrices

3 visualizaciones (últimos 30 días)
Anas Khan
Anas Khan el 26 de Nov. de 2020
Editada: Ameer Hamza el 26 de Nov. de 2020
I want to split up a large matrix (Vdata) with 768 columns of data into 12 matrices, each with 64 columns of data. I could do this by hand and assign each matrix the correct columns, but I want this to be end-user friendly and be able to be done by just running a script. I have come up with the code below thus far. But, I can't seem to figure out how to use a third looping variable to create new matrices for example (Col1 to Col12 in steps of 1: Col1, Col2, Col3,...).
n = [64:64:768];
m = n-63;
for i = m
for j = n
Col = Vdata(:,i:j);

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 26 de Nov. de 2020
Editada: Ameer Hamza el 26 de Nov. de 2020
Naming variables like Col1, Col2, ... is a very bad coding practice: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. It is much easier to use cell arrays. For example
Vdata = rand(100, 768);
Col = mat2cell(Vdata, size(Vdata, 1), 64*ones(size(Vdata, 2)/64, 1));
Col is a cell array with each element having 64 columns.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by