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
