matlab: creating additional variables in a for loop -


i got following problem: in code want matrix-...-matrix-vector in loop. in every loop want additional matrix multiply with, e.g. i=1: p1*z , i=2: p1*p2*z etc. code far. computing: i=1: p1*z, i=2: p2*z etc...

for ii = 1:10     % projection on last_z     projected_last_z = projection(:,:,ii) * last_z; end 

it considered bad practice create new variables in loop want. better collect results in cell array or so:

n = 10; results = cell(1, n);  % preallocate space = 1:n     results{i} = some_calculation(i); end; 

you can retrieve result of k-th iteration using results{k}.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -