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 ExchangeLoops 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