How to create a 5D matrix by repeating a 2D array?
6 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm trying to create a 5D matrix from a 2D array by repeating it for each array in the 5D matrix. I managed to do it using for loop.
A = zeros(1,70); % 2D array
X = zeros(length(N),length(lg),length(C),length(E),length(A)); %% 5D matrix
for p = 1:1:length(A)
X(:,:,:,:,p)=A(p);
end
Is there any shorter way to do this?
Thanks.
0 个评论
采纳的回答
Fangjun Jiang
2020-7-27
A has 70*70 elements. The loop runs only 70 times.
Anyway, look into repmat(), reshape(),repelem().
3 个评论
Fangjun Jiang
2020-7-27
编辑:Fangjun Jiang
2020-7-27
A=1:5;
X=zeros(2,3,5);
X=reshape(repelem(A,2*3),2,3,[])
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!