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

1 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by