Write a script to determine whether an input is scalar row v

Write a script to determine whether an input is \'scalar\', \'row vector\', \'column vector\' or \'matrix\'.

Solution

% taking user input
prompt = \"Enter input :\";
x = input(prompt);

% checking whether input is scalar
if isscalar(x) == 1
fprintf(\"Input is a Scalar\ \"); % printing scalar
% checking whether input is row vector
elseif isrow(x) == 1
fprintf(\"Input is a row vector\ \"); % printing row vector
% checking whether input is column vector
elseif iscolumn(x) == 1
fprintf(\"Input is a column vector\ \"); % printing column vector
% checking whether input is matrix
else ismatrix(x) == 1
fprintf(\"Input is a matrix\ \"); % printing matrix
end

---------------------------------------------------------------------

SAMPLE OUTPUT

Enter input :30                                                                            

Input is a Scalar

Enter input :[1 2 3]                                                                       

Input is a row vector

Enter input :[4 5 6]\'                                                                      

Input is a column vector

Enter input :[1 2 3; 4 5 6;]                                                               

ans =  1                                                                                   

Input is a matrix

 Write a script to determine whether an input is \'scalar\', \'row vector\', \'column vector\' or \'matrix\'.Solution% taking user input prompt = \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site