MATLAB Assingment-Use character arrays to display an input type

1 view (last 30 days)
Write a function that accepts an input argument that is one of 3 things: a vector, a matrix, or a scalar of values. The function should return an output argument that contains a character array that reads: 'vector', 'scalar', or 'matrix'. Make sure that each of these is all lower case exactly as written or your work will evaluate as incorrect!!! You are not displaying the words vector, scalar, or matrix. You are returning variable y that has a value of vector, scalar, or matrix.
Im very new to coding and am confused how i go about this problem. I started with
function y = findargtype(x)
if y==ismatrix(x)
y=char(matrix)
elseif y==isscalar(x)
y=char(scalar)
elseif y==isvector(x)
y=char(vector)
end
but it says y is unknown. Any help would be appreciated!
Code to run-
s=5;
y=findargtype(s)
rv=randi(10,1,5);
y=findargtype(rv)
cv=randi(10,5,1);
y=findargtype(cv)
M=randi(10,randi([4,8]));
y=findargtype(M)
  5 Comments
Steven Lord
Steven Lord on 19 Mar 2024
And to create the character array to return, just use single quotation marks like the first segment of code in the Represent Text with Character Vectors section on that documentation page. This was the first hit when I searched the documentation for the phrase "character array".
Riley
Riley on 19 Mar 2024
That really cleared things up i assumed since it said not to display the words I had to do somethign else. Both of you helped very muchthank you I appreciate it!

Sign in to comment.

Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!