How to preallocate 3 D matrix?

92 views (last 30 days)
reshdev on 6 Sep 2014
Commented: Yu Jiang on 6 Sep 2014
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(:,:);
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

Accepted Answer

Yu Jiang
Yu Jiang on 6 Sep 2014
Edited: Yu Jiang on 6 Sep 2014
outp(:,:,u)= zeros(5, 10, n)
Yu Jiang
Yu Jiang on 6 Sep 2014
Your version is much better :)

Sign in to comment.

More Answers (0)


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by