use the if-else loop considering a variable 'char' in the workspace

Hi! I have an 'out' variable in the workspace that can be a number or a char. How can I use the if-else loop considering this variation of the variable 'out'?
For example:
out = 'analysis'; % or number
if out % 'out' is char
text = out;
else % 'out' is number
% ....
end

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 12월 1일
편집: Dyuman Joshi 2023년 12월 1일
You can use ischar and isnumeric -
out = 'analysis'; % or number
if ischar(out)
disp('character')
elseif isnumeric(out)
disp('numeric data')
else
disp('Unknown data')
end
character
Note that if, elseif, else is not a loop, but a group of conditional statements/blocks.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 12월 1일

편집:

2023년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by