Stacking multiple arrays into a matrix
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
HEMRAJ PATEL
am 13 Nov. 2021
Kommentiert: HEMRAJ PATEL
am 13 Nov. 2021
How can i form a matrix out of n number of different column matrices of same size by placing them side by side.
0 Kommentare
Akzeptierte Antwort
Dave B
am 13 Nov. 2021
Bearbeitet: Dave B
am 13 Nov. 2021
You can make append two columns like this:
a=rand(10,1);
b=rand(10,1);
c=[a b];
size(c)
or like this:
c=cat(2,a,b);
size(c)
Both approaches extend to n columns:
a=rand(10,1);
b=rand(10,1);
c=rand(10,1);
d=rand(10,1);
M1=[a b c d];
size(M1)
M2=cat(2,a,b,c,d);
size(M2)
Alternatively, you could initialize a matrix and then fill it with the columns:
M3=nan(numel(a),4); % you don't really need to initialize, but it is wise
M3(:,1) = a;
M3(:,2) = b;
M3(:,3) = c;
M3(:,4) = d;
size(M3)
6 Kommentare
Stephen23
am 13 Nov. 2021
"if i have 2000 matrices like (c1,c2,c3,...,c2000) and i want them in cat function. How will i do it."
I have some ideas of how you might do it, but no experienced MATLAB users would do that.
"Do i have to write c=cat(2,c1,c2,c3....) or do we have another option"
Another option is better data design: don't have numbered variable names.
Numbered variable names is a sign that you are doing something wrong. Use indexing instead.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!