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

1 次查看(过去 30 天)
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

采纳的回答

Thomas
Thomas 2012-5-22
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 个评论
Thomas
Thomas 2012-5-22
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by