% This code prints 3 matrices %

for i=1:4 % create matrices a and b
    for j=1:5
        a(i,j) = 10/(i+j);
        b(i,j) =  2*(i-j);
    end
end
for i=1:5 % create matrix c
    for j=1:6
        c(i,j) = 10/(2*i+j);
    end
end
[Ha,Wa]=size(a); % determine dimensions of matrix a
[Hb,Wb]=size(b);
[Hc,Wc]=size(c);

fid = fopen('print_matrix.txt','wt'); % create a new file for printing the matrices
fprintf(fid,'Matrix a \n');  % Header for matix a
fprintf(fid,'row/col');
for i=1:Wa
    fprintf(fid,'%7.0f ', i);
end
for i=1:Ha
    fprintf(fid,' \n %7.0f', i);
    for j=1:Wa
        fprintf(fid,'%8.4f', a(i,j));
    end
end
fprintf(fid,'\nMatrix b \n'); % Header for matix b
fprintf(fid,'row/col');
for i=1:Wb
    fprintf(fid,'%7.0f ', i);
end
for i=1:Hb
    fprintf(fid,' \n %7.0f', i);
    for j=1:Wb
        fprintf(fid,'%8.4f', b(i,j));
    end
end
fprintf(fid,'\nMatrix c \n'); % Header for matix c
fprintf(fid,'row/col');
for i=1:Wc
    fprintf(fid,'%7.0f ', i);
end
for i=1:Hc
    fprintf(fid,' \n %7.0f', i);
    for j=1:Wc
        fprintf(fid,'%8.4f', c(i,j));
    end
end



