Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Alberto Acri
Alberto Acri le 1 Déc 2023
Modifié(e) : Dyuman Joshi le 1 Déc 2023
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

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 1 Déc 2023
Modifié(e) : Dyuman Joshi le 1 Déc 2023
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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by