1. Write the \"rowcolnum\" function IN MATLAB as discussed in class. Below is th
ID: 3758118 • Letter: 1
Question
1. Write the "rowcolnum" function IN MATLAB as discussed in class. Below is the beginning of the function (you may copy/paste this part). Use vector and matrix operations. DO NOT USE LOOPS. Check that the input values (r and c) are legal (integers and >= 1) and if they are not legal print an error message and return an empty vector. Demonstrate that it works by testing it using the following five cases (for some cases you may choose the exact values, but keep both r and c less than 10): (a) r=c=1, (b) r=1,c>1, (c) r>1,c=1, (d) r>2,c>2, and (e) an illegal input.
function X = rowcolnum (r,c)
% X = rowcolnum (r,c)
% create a matrix with r rows and c columns containing values 10*row+col
% e.g. X=rowcolnum(2,3) results in X=[11 12 13 ; 21 22 23]
% this is useful for demonstrating matrix row and column manipulations
% note: if r or c is larger than 9 this is not particularly useful
Explanation / Answer
CODE :
To check for test cases :
a) r=c=1
if both row and column are 1 then we get 1 element in matrix.
b) r=1, c>1
if row is one and column is greater than one then it should be displayed in matrix.
c) r>1, c=1
if row is greater than one and column is one then it should be displayed in matrix.
d) r>2, c>2
if both row and column is greater than 2 then is should be displayed in matrix.
e) an illegal input
if row and column is illegal then nothing to be displayed in matrix.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.