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')endThe output should be:[1 1 11 1 11 1 1 2 2 22 2 22 2 23 3 33 3 33 3 34 4 44 4 44 4 45 5 55 5 55 5 56 6 66 6 66 6 6]
Best Answer