MATLAB Assingment-Use character arrays to display an input type
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Steven Lord
am 19 Mär. 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".
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!