Azzera filtri
Azzera filtri

Loop to Organize Matrices

3 visualizzazioni (ultimi 30 giorni)
Anas Khan
Anas Khan il 26 Nov 2020
Modificato: Ameer Hamza il 26 Nov 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);

Risposta accettata

Ameer Hamza
Ameer Hamza il 26 Nov 2020
Modificato: Ameer Hamza il 26 Nov 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.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by