Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer it all and provide the also the code for each part 1) The dlmwrite

ID: 3565873 • Letter: P

Question

Please answer it all and provide the also the code for each part

1) The dlmwrite functions allows us to easily write matrices to files. dlmwrite documentation: http://www.mathworks.com/help/matlab/ref/dlmwrite.html a) Assume we have a matrix, M. Using the dlmwrite function, write the MATLAB code to write the matrix to a file named myfile.txt, and have the content of the matrix be separated by commas. ) What would you change if you wanted the matrix elements to be separated by a space instead of a comma? 2) Practice for loops by iterating through matrices, complete the following sections: a) Write the MATLAB code to create a 5x5 matrix of zeroes. Store it in a variable named M. b) Write the MATLAB code to change the diagonals of M from 0?s to 1?s (Hint: Draw the matrix out if you need to visually see this).

Explanation / Answer

M=input('enter the matrix');
%% writing the matrix with comma separated
%% the default option of dlmwrite function is comma separated

dlmwrite('myfile.txt',M);


%% to write with space

dlmwrite('myfile1.txt',M,'delimiter',' ');


Q2.

M=zeros(5,5);

for i=1:5
M(i,i)=1;
end
disp('new matrix is ')
disp(M)