MATLAB Assingment-Use character arrays to display an input type
조회 수: 2 (최근 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!