These instructions must be followed exactly or you will not receive credit for t
ID: 1932128 • Letter: T
Question
These instructions must be followed exactly or you will not receive credit for this exam.
1. Write an m-file that solves the problem you have been assigned.
2. Put the text of the problem into the file as a comment.
3. Include your name in the file as a comment.
4. Turn in the m-file on blackboard. Do not copy and paste the text into blackboard.
Problem:
Create a function that takes a matrix as an input. The function returns another matrix that has the last two columns switched if the number of columns is greater than the number of rows or has the last two rows switched if the number of rows is greater than the number of columns.
Explanation / Answer
%Create a function that takes a matrix as an input. The function returns another matrix %that has the last two columns switched if the number of columns is greater than the %number of rows or has the last two rows switched if the number of rows is greater %than the number of columns. %write your name. function [x]=myfunction(y) [a,b]=size(y); x=zeros(a,b); if a>b x(1:a-2,:)=y(1:a-2,:); x(a-1,:)=y(a,:); x(a,:)=y(a-1,:); else x(:,1:b-2)=y(:,b-2); x(:,b-1)=y(:,b); x(:,b)=y(:,b-1); end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.