Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Guillermo Lopez
Guillermo Lopez le 22 Mai 2012
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

Réponse acceptée

Thomas
Thomas le 22 Mai 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 commentaires
Thomas
Thomas le 22 Mai 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 le 22 Mai 2012
But this wouldn't save it on the same matrix would it?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by