Store all iteration loop outputs in a file
Show older comments
Hi, I am writing a program with a loop where the output from every iteration is a matrix with the same size (the size of the matrix is very large). However, I want to save the output from each iteration in a file (and not to create another variable (matrix or a vector)), as the number of iterations is more than 100 000 (needed for Gibbs sampling). I need to save the output from each iteration in a file (ex. .mat or txt) as storing it in a new variable might consume more RAM than my computer has available. I need to read the results from the file and do further calculation. I was recommended to use 'save' but I don't know how to save the output from all iterations as the name of the matrix (b) is the same and it is overwritten after each iteration, if I use the '-append'.
Simple example of the program is:
a=[1 1 1; 1 1 1; 1 1 1];
b=[];
for i=1:6
b=a.*i
save('test.mat','b', '-append')
end
The output should be:
[1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3
4 4 4
4 4 4
4 4 4
5 5 5
5 5 5
5 5 5
6 6 6
6 6 6
6 6 6]
Accepted Answer
More Answers (0)
Categories
Find more on Variables 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!