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

IC Challenge 6.6.1: Deleting rows and columns colon operator using the This acti

ID: 3799164 • Letter: I

Question

IC Challenge 6.6.1: Deleting rows and columns colon operator using the This activity uses a 3rd party app. Though your activity may be recorded, a refresh may be required to update the banner to t Ex: is[1. 2. 4. 9, 5. 6. 7. 8. 1. delRow is 1. and delCol is 2, then newMatrix A is I4, 5. 6, 8. 1. and deletedElems 3, 2, 9, 7.1 1 3 2 delRow origMatrixA -4 9 5 deletedElems 2 6 8 6, 7 8 delCol Your Solution Ba Save e Reset MATLAB Documentatio 1 function newMatrixA, deletedElems 1 DeleteRowcolumn origMatrixA, delRow, delcol DeleteRowcolumn: Delete the row and column specified by delRow 3 and delCol from input matrixA and returns the modified matrix and 4 the deleted elements as a column array. Inputs origMatrixA input matrix 6 96 del Row now to delete delcol column to delete 9 outputs new MatrixA- nput matrix with specified row and column deleted. deletedElems deleted elements from input matrix 100 returned as column array

Explanation / Answer

Matlab code:

function [newmatrix, deleted_elements] = deleterowcolums(original,row,col)
tmp = [];
deleted_elements = [];
for i = 1:size(original,1)
if(i ~= row)
tmp = [tmp; original(i,:)];
else
deleted_elements = [deleted_elements; (original(i,:))'];
end
end
tmp2 = [];
for i = 1:size(tmp,2)
if(i ~= col)
tmp2 = [tmp2; tmp(:,i)];
else
deleted_elements = [deleted_elements; tmp(:,i)];
end
end
newmatrix = tmp2;
end

Sample Input(): ([1,3,2;4,9,5;6,7,8], 1, 2)

Sample Output():