Is there an 'Is___' Function that Checks if a Value is a [ ]?
Mostra commenti meno recenti
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
Più risposte (1)
Walter Roberson
il 23 Ago 2023
1 voto
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
Jon
il 23 Ago 2023
Walter Roberson
il 23 Ago 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.
Categorie
Scopri di più su Resizing and Reshaping Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!