Using MatLab write the \"rowcolnum\" function as discussed in class. Below is th
ID: 3758079 • Letter: U
Question
Using MatLab write the "rowcolnum" function 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
Solution :
Checking for test cases :
a) r=c=1
if both row and column is 1 then only 1 value will be displayed in matrix.
b) r=1, c>1
if one row and more then one column then it should be displayed on the screen.
c) r>1, c=1
if row is more than one and column is one then is should be displayed on the screen.
d) r>2, c>2
if both row and column more than two then matrix should be greater matrix only.
e) an illegal input gets when no values given for row and column.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.