我正在使用 matlab 制作一个 3 维数组,它按照某种模式进行。虽然我可以手动写出数组,但我确信有一种更快的方法来做到这一点。
multiArray = cat(3,...
[1+randn(4,3); 1*randn(4,3)],...
[2+randn(4,3); 2*randn(4,3)],...
[3+randn(4,3); 3*randn(4,3)]);
如果我想让上面的数组为 8x3x25 那么最后一行就是
[25+randn(4,3); 25*randn(4,3)]
但是我怎样才能在不经历所有繁琐的干预步骤的情况下制作这样的数组呢?
最佳答案
同时mikkola basically got the solution ,最后不需要改变尺寸。
s=[4,3,25];
it=reshape(1:s(3),1,1,[]);
out = [bsxfun(@plus , it, randn(s));...
bsxfun(@times, it, randn(s))];
关于matlab - 按照模式创建多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33734820/