stacking of large matrix into stack of small column matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello here i want to put row of w matrix as a column vector in w_stack for i as a number of element. i.e each row of w corresponds to each element which i want it a column vector. can you please help me
nele = 8;
w = zeros(nele,3);
w = [0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 -2;
0 0 -2;
0 0 -2;
0 0 -2];
w_trans = w';
W = w_trans(:);
w_stack = zeros(3,1,nele);
for i = nele
w_stack(1:3,1,i) = w(1:w(1:3, 1, i)';
end
0 Kommentare
Antworten (1)
DGM
am 26 Nov. 2022
I'm not really sure what exactly you want, but I'm going to take a guess anyway. I'm going to assume that nele is possibly less than size(w,1). I'm going to interpret your original prototype code as to be:
nele = 8;
w = [0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 -2;
0 0 -2;
0 0 -2;
0 0 -2];
w_stack = zeros(3,1,nele);
for i = 1:nele
w_stack(:,1,i) = w(i,:);
end
w_stack
If that's a correct interpretation of your goal, then you can replace that with one line:
wstack = permute(w(1:nele,:),[2 3 1])
... and the results are the same.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures 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!