save instruction
1 view (last 30 days)
Show older comments
Hi, This is an elementary question related to Matlab Programming. I am using a loop in main body of program and this loop execute 50 times for "x" variable. I would like to save values of "x" in a mat file after each execution. If I am using save ("filename", x) within the loop it saves only last value of the variable "x". Please let me know, can I save each value of "x" in a file (like a vector). Do you think I need to make a data set. Thank you, Neeta
0 Comments
Accepted Answer
Thomas
on 12 Mar 2012
You would rather do well to save the data in a vector than write a mat file every time the loop runs:
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:
z=[];
for i=1:10
z=[z i+rand];
end
0 Comments
More Answers (0)
See Also
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!