ays using the end keyword ActMy 6,9,1 Swapping last matrix columns This activity
ID: 3790657 • Letter: A
Question
ays using the end keyword ActMy 6,9,1 Swapping last matrix columns This activity uses a party app Though your actety may be rocondedamfresh maybe required to update me banner to the swapping last matrix columns. Saap the last column of matrtxAwith the last column of matridB. Note: Both matrices will have the same number of rows, butmay have dmerent numbers of columns. ExIt matrixAis13, 14:15, 9:1 and matroBis12, 7:1.8: nen newMatmKA is13, 7:15, 8:1 and newMatixB is 12, 14 1.9.1. a Save CReset MATLAB Documentation Your Solution function nevMatrixA, trixB 1 swapuastcolunns( natrixA, natrixe newMat Swaplastcolunns: Exchange the last columns of input matrices 2 S matrixA and matrixB and return new matrices 4 Inputs: natrixA. natrixB input matrices must have same number of rows so columns can be swapped v Outputs nevMatrix, nevMatrixu returned new natrices created from input matrices with last columns swapped 12 Assign tempcolumn with tast column matrixA tenpoolumn matrixA Assign nevMatrixA with first columns of natrix, and Last column of natrixB newMatrixA matrixA: FDME 19 v Assign newMatrixB with first columns of matrix and Last colunn of matrixA meeMatrixB matrix FIUMEExplanation / Answer
% matlab code
function [newMatrixA, newMatrixB] = SwapLastColumns (matrixA, matrixB)
% assign tempColumn with last column of matrixA
tempColumn = matrixA(:,end);
%assign newMatrixA with first column of matrixA and last column of matrixB
newMatrixA = [matrixA(:,(1:end-1)), matrixB(:,end)];
%assign newMatrixB with first column of matrixB and last column of matrixA
newMatrixB = [matrixB(:,(1:end-1)), matrixA(:,end)];
end
[newMatrixA, newMatrixB] = SwapLastColumns ([32,-4,5;7,8,17;0, -9, -11;], [6,2;1,3;-10,55;]);
disp("newMatrixA: ");
disp(newMatrixA);
disp("newMatrixB: ");
disp(newMatrixB);
%{
output:
newMatrixA:
32 -4 2
7 8 3
0 -9 55
newMatrixB:
6 5
1 17
-10 -11
%}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.