Automated Savings and Loadings using multiple files - Use a loop to generate mul
ID: 3687482 • Letter: A
Question
Automated Savings and Loadings using multiple files
- Use a loop to generate multiple magic matricies of size 20, 25, 30, 35, 40, 45, 50
-In the same loop generate a file named magicmatrix_i where i takes the value of 1-7 as the loop index advances
-Use save and eval to generate magic matrix in the corresponding file, ie magic(20) should be saved as magicmatrix_1 and magic(25) should be magicmatrix_2
-clear the workspace of all variables. Use load and eval in another loop to load each of the 7 files just saved and to image the matrix using image(A) command in the figure window figure(i) where i is the index
Explanation / Answer
size = [20, 25, 30, 35, 40, 45, 50];
a = NaN(7,51);
for i=1:7
a(i,1:size(i))=magic(size(i));
filename=strcat("magicmatrix","_",str(i),".txt");
fileID = fopen(filename,'w');
fprintf(fileID,'%5d %5d %5d %5d ',a(i))
fclose(fileID);
end
CLW
for i=1:7
filename=strcat("magicmatrix","_",str(i),".txt");
a(i) = importdata(filename)
disp(eval(a(i)))
image(A)
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.