MATLAB Assingment-Use character arrays to display an input type

1 次查看(过去 30 天)
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 个评论
Steven Lord
Steven Lord 2024-3-19
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 2024-3-19
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!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by