stacking of large matrix into stack of small column matrix
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
DGM
2022-11-26
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!