Effacer les filtres
Effacer les filtres

Is there an 'Is___' Function that Checks if a Value is a [ ]?

2 vues (au cours des 30 derniers jours)
Jon
Jon le 23 Août 2023
Commenté : Walter Roberson le 23 Août 2023
Hello,
I know there are functions like istable, which checks if a given variable is a Table (1) or not a table (0).
Is there one that checks if a variable's value is a [ ]?
I'm not sure what it is called, but I have a script that takes in tables of a heater turning on or off.
Column A is time, and Column B is either a 1 for On or a 0 for Off.
In some cases that heater doesn't turn on, but if I don't catch it before I run the script, I get an error message.
There are a couple variables that get affected by this and give values with a [ ] in the workspace window.
I'd like to have a big if/else statement that says something like:
if variable is a [ ]
disp('The heater does not turn off')
else
%The rest of my code as normal
end
Let me know if this doesn't make sense, I can try to elaborate further.
Thanks.

Réponse acceptée

Voss
Voss le 23 Août 2023
Modifié(e) : Voss le 23 Août 2023
  1 commentaire
Jon
Jon le 23 Août 2023
Sweet thanks, must've missed that one while looking

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 23 Août 2023
isempty -- though isempty tests for any datatype that has a dimension of length 0 .
If you want to specifically test for [] then you should test isdouble(variable) && isequal(variable, [])
Note that if you have a table with a numeric variable, then the variable entry can never be [] -- the variable would have to be a cell array in order for an entry to be []
  2 commentaires
Jon
Jon le 23 Août 2023
Cool thanks.
I think having it test for a zero dimension would still give me what I want, mainly that my one variable that looks for when the heater is on will give zero if the heater is never on.
Walter Roberson
Walter Roberson le 23 Août 2023
Sounds like you are doing a find(). If so, then isempty() works well for that.
If it does happen to be a find() situation, then it turns out that there a number of situations in which it is more efficient to use logical indices instead of find(). Not always, though... sometimes find() is best.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by