How to add a "if not a number" expression to GUI error dialog

Hi, I'm making a GUI and is trying to add error dialogs to it. I have an input pressure P, and was wishing to set minimum and maximum boundaries for the GUI to either work or show error dialogs. However when I used P=NaN to make an expression for a non-numerical input (like P=apple where apple is not defined numerically) I got error messages telling me that "the expression to the left of the equals sign is not a valid target for an assignment". What could I do instead?
Here is my code:
P = str2num(get(findobj('tag','gP'),'string'));
if P>550.7921
elseif P<0
elseif P=NaN
errordlg('No solution','Error')
return
end

1 Commento

As an aside: use str2double rather than str2num: this guarantees only numeric scalars in the output, and avoids the eval inside str2num.

Risposte (1)

M
M il 2 Mar 2018
Modificato: M il 2 Mar 2018
Are you searching for somethink like isnan ?
if isnan(P)
errordlg('...');
end

Questa domanda è chiusa.

Tag

Richiesto:

il 2 Mar 2018

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by