Help me to figure out the code for this problem. Could be type on a computer or
ID: 3349152 • Letter: H
Question
Help me to figure out the code for this problem. Could be type on a computer or in a piece of paper. DO NOT USE BUILD IT FUNCTIONS IN MATLAB LIKE SWAP Given inputs of a random matrix A, a first row to swap, and a second row to swap, produce the matrix A with swapped rows. Label your program lastnome. firstinit ME3430 Activity9.m. Test your program with the following matrix: 1 2 3 If your first line reads as follows function A-swapped = kabir-a-ME 3430-Activity9(Arowl.row2) Then, if you swapped rows 2 and 4, the new matrix would look like 3 1 2 Additionally, if the user asks to swap rows that don't existw 2 with row s), you should display a message that states the user made an error. There should be no actual Matlab error message. Use wappedA 11 to output an empty matrix in the event of a user errorExplanation / Answer
Matlab Script:
function A_swapped = kabir_a_ME3430_Activity9(A,row1,row2)
[r c] = size(A);
if row1>r || row2>r
error('given choice of row doesnot exist');
A_swapped = [];
else
temp = A(row1,1:c);%storing row1 temp
%swapping
A(row1,1:c) = A(row2,1:c);
A(row2,1:c) = temp;
A_swapped = A;
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.