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
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".
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!