If statement for identifying row/column vectors/matrix/scalars
조회 수: 37 (최근 30일)
이전 댓글 표시
The question I am trying to solve, is how to create a function that recognizes the input given as either a colum vector, row vector, matrix, or scalar, depending on which category the input falls under it will execute simple arithmetic, that I can do. I have to create a function, myvec(x) that
the simple arithmetic I can execute, however, Im not sure how to type the if statements for the conditions the question prompts, for example, for the first condition how would I type
function y=myvec(x)
if y=rowvec? [1:n]? [1,n]?
or what is the correct way to do this, thank you
댓글 수: 0
답변 (1개)
Sudhakar Shinde
2020년 11월 3일
편집: Sudhakar Shinde
2020년 11월 3일
'isrow' function returns true if input is row vector.
isrow(in)
'iscolumn' function returns true if input is column vector.
iscolumn(in)
'ismatrix' function returns true if input is matrix.
ismatrix(in)
'isscalar' function returns true if input is scalar.
isscalar(in)
댓글 수: 2
Sudhakar Shinde
2020년 11월 3일
example below
function y=myvec(x)
if isrow(x) %Check if row vector
ReveresRow = sort(x,'descend'); %Reverse elements
y = ReveresRow.^2; %Square
end
end
you can add else if conditions for column vector, matrix or scalar
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!