Write a function to determine whether the input arguments is

Write a function to determine whether the input arguments is a scalar, a vector, or a matrix? Solution function y = findType(A) y = A; end

Solution

function y = findType(A)
[r c]=size(A);%gives the number of rows and columns
if r==1 && c==1
y = \'scalar\';
elseif r==1 && c>1
y=\'vector\';
else
y=\'matrix\';
end
end

Command window output:

>> findType([1 2 3])

ans =

vector

>> findType([1])

ans =

scalar

>> findType([1 2 3; 4 5 6])

ans =

matrix

>>

 Write a function to determine whether the input arguments is a scalar, a vector, or a matrix? Solution function y = findType(A) y = A; endSolutionfunction y =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site