how to stack a 2D matrix form in 3D form?
1 次查看(过去 30 天)
显示 更早的评论
Could anyone suggest me some hint to solve this problem. i have a 3D matrix A=6*3*6 and length(U)=3 where U values are 3,4,5. I want the updated calculation of A in 3D form. how can we do that?
for j=1:length(U)
M=A(U(j),1,2)* A(:,:,U(j));//stack 1
//stack 2 value will be for the next iteration i.e U(2)=4
//stack 3
How can i get a 6*3*length(U) ?
0 个评论
采纳的回答
DGM
2021-11-25
Something like this
A = randi(9,[6 3 6]);
U = 3:5;
% do it with a loop
M = zeros(size(A,1),size(A,2),numel(U));
for k = 1:length(U)
M(:,:,k) = A(U(k),1,2) * A(:,:,U(k));
end
Alternatively, this can be vectorized like so:
% if you're running R2016b or newer
M2 = permute(A(U,1,2),[3 2 1]).*A(:,:,U);
% show that this is the same as using the loop
immse(M,M2)
% if you're running R2016a or older
M3 = bsxfun(@times,permute(A(U,1,2),[3 2 1]),A(:,:,U));
% show that this is the same as using the loop
immse(M,M3)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!