How to preallocate 3 D matrix?

61 次查看(过去 30 天)
Hello,
Suppose output(:,:) is matrix with 5 rows and 10 columns.
u is from 1 to n. So, i will have n different output(:,:) matrix's which i am saving in outp(:,:,u).
for u= 1:n
outp(:,:,u) = output(:,:);
end
then how can i pre allocate outp(:,:,u) with zeros so that i can increase speed.
will it be outp(:,:,u)= zeros(5*n,10)?
Thank You

采纳的回答

Yu Jiang
Yu Jiang 2014-9-6
编辑:Yu Jiang 2014-9-6
outp(:,:,u)= zeros(5, 10, n)
  2 个评论
Guillaume
Guillaume 2014-9-6
Or even simpler:
outp = zeros(5, 10, n);
What you wrote works (if outp didn't exist), it's very confusing.
Yu Jiang
Yu Jiang 2014-9-6
Guillaume
Your version is much better :)
-Yu

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by