Saving values in workspace automatically for a loop
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have a script as :
for k=1:6
    x=3+k;
   y=4+k
   z=x+y;
I would like to save the values of x, y and z stored in workspace for each ietration on my laptop automatically with increment names...
How can i do that..
Thanx
0 comentarios
Respuesta aceptada
  Thomas
      
 el 21 de Mayo de 2013
        
      Editada: Thomas
      
 el 21 de Mayo de 2013
  
      This video should help:
You can save the output in a vector or matrix as shown,
Eg:
% Preallocate space for y
y = zeros(1,10); 
for ii=1:10
y(ii)=i+rand;  % use y(ii) so that it is written as a vector
end
 y(2) %output of 2nd iteration
0 comentarios
Más respuestas (1)
  Jan
      
      
 el 21 de Mayo de 2013
        "Incremented names" sounds like "A1, A2, A3, ...". If you want this: Don't do it. See FAQ: How to create variables A1, A2, ... in a loop.
Your example could be solved by:
k = 1:6;
x = 3+k;
y = 4+k;
z = x+y;
Now z(3) is the value from the 3rd iteration, but this is Matlab stylish written without a loop.
0 comentarios
Ver también
Categorías
				Más información sobre Loops and Conditional Statements 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!


