Borrar filtros
Borrar filtros

saving a changing variable into one table on a different row each time.

2 visualizaciones (últimos 30 días)
I think the question is self explanatory. I have a variable (say n_value) which changes value with a loop. How would you save it into one mat file (a table of values) with a new row for each value of the same variable? This way I can then call the variables again by using just one table. Thanks

Respuesta aceptada

Thomas
Thomas el 22 de Mayo de 2012
you need to save the value in a for loop This video should help:
You can save the output in a vector or matrix as shown,
Eg:
for i=1:10
y(i)=i+rand; % use y(i) so that it is written as a vector
end
or you could use:
% preallocate variable here
for i=1:10
z=[z i+rand];
end
both should give you similar results..
  3 comentarios
Thomas
Thomas el 22 de Mayo de 2012
for two variables, you could save it in the save for loop with different variable name:
for i=1:10
y(i)=i+rand; % variable 1
m(i)=i^2+rand; %variable 2
end
you have two vectors of output variables y and m
Guillermo Lopez
Guillermo Lopez el 22 de Mayo de 2012
But this wouldn't save it on the same matrix would it?

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by