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

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.

 Risposta accettata

Voss
Voss il 23 Ago 2023
Modificato: Voss il 23 Ago 2023

Più risposte (1)

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 Commenti

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

Accedi per commentare.

Categorie

Prodotti

Release

R2022a

Richiesto:

Jon
il 23 Ago 2023

Commentato:

il 23 Ago 2023

Community Treasure Hunt

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

Start Hunting!

Translated by