Borrar filtros
Borrar filtros

How do you store variables atfer each iteration of a for loop to use later?

1 visualización (últimos 30 días)
Mark
Mark el 16 de Mzo. de 2014
Editada: per isakson el 16 de Mzo. de 2014
I'm running a for loop , and each time I run through the loop at the end I want to store two variables (arrays) to be used later. i.e
for n=1:94
u = [n,n+1,n+2]
v = [n,n*1,n*2]
end
For n equal 1 I want to store u and v and the for n =2 I want to store u and v (and so on) separately and without them over writing each other! Effectively I want to create a separate variable for u when n=1 and when n=2 and likewise for v.
Any suggestions?
Thanks

Respuestas (1)

per isakson
per isakson el 16 de Mzo. de 2014
Editada: per isakson el 16 de Mzo. de 2014
Try
u = nan(94,3);
v = nan(94,3);
for n=1:94
u(n,:) = [n,n+1,n+2];
v(n,:) = [n,n*1,n*2];
end

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by