Clear Filters
Clear Filters

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

2 views (last 30 days)
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

Accepted Answer

Thomas
Thomas on 22 May 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 Comments
Thomas
Thomas on 22 May 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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!