Filter löschen
Filter löschen

Loop to Organize Matrices

3 Ansichten (letzte 30 Tage)
Anas Khan
Anas Khan am 26 Nov. 2020
Bearbeitet: Ameer Hamza am 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);

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 26 Nov. 2020
Bearbeitet: Ameer Hamza am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by