Write a function named swap to swap two rows in a matrix You

Write a function, named swap, to swap two rows in a matrix. You will pass the matrix and two row numbers to exchange.

Solution

function matrix = swap(M, row1, row2)
col = length(M, 1);
for i = 1:col
temp = M(row1,i);
M(row1,i) = M(row2,i);
M(row2,i) = temp;
end
matrix = M;
end

Write a function, named swap, to swap two rows in a matrix. You will pass the matrix and two row numbers to exchange.Solutionfunction matrix = swap(M, row1, row

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site