Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Thomas
Thomas il 22 Mag 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 Commenti
Thomas
Thomas il 22 Mag 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by