Azzera filtri
Azzera filtri

check if numeric field is empty in app designer

15 visualizzazioni (ultimi 30 giorni)
reaujahn
reaujahn il 12 Gen 2022
Modificato: Voss il 12 Gen 2022
Hello,
I have 4 numeric edit fields, that are responsible for controlling the limits of the x and y axis, if a value is assigned to it. I did it because I want sometimes to zoom in a certain area of the plot but sometimes I want to see the whole plot in the auto mode, without tipping the values.
I wrote the following code:
if ~isempty(app.xMin)
if ~isempty(app.xMax)
xlim(app.UIAxes,[app.xMin app.xMax]);
end
end
if ~isempty(app.yMin)
if ~isempty(app.yMax)
ylim(app.UIAxes,[app.yMin app.yMax]);
end
end
When plotting the curve without values in the edit fields I get following error:
Error using xlim (line 31)
Limits must be a 2-element vector of increasing numeric values.
Error in app2/CurvePlotDropDownValueChanged (line 117)
xlim(app.UIAxes,[app.xMin app.xMax]);
Error while evaluating DropDown PrivateValueChangedFcn.
I would appreciate if someone know how can I deal with this problem.
Thanks!

Risposte (1)

Voss
Voss il 12 Gen 2022
Try changing line 117 of app2 (/CurvePlotDropDownValueChanged) to:
xlim(app.UIAxes,[app.xMin app.xMax]);
Note the xMax was first in the error message. This indicates the code you shared is not the code causing the error, so you may also need to check that ~isempty(app.xMin), etc.
  2 Commenti
reaujahn
reaujahn il 12 Gen 2022
Hello Benjamin,
thanks for your help!
I actually changed the name of the properties app.xMin app.xMax to be easier to understand what I am talking about. That was a mistake while I was writing the question here. In my code I have the correct order of properties.
Do you have maybe another idea what the problem could be?
Voss
Voss il 12 Gen 2022
Modificato: Voss il 12 Gen 2022
Assuming that this is the line that causes the error:
xlim(app.UIAxes,[app.xMin app.xMax]);
and that the line is used in the context you shared (repeated here for clarity)
if ~isempty(app.xMin)
if ~isempty(app.xMax)
xlim(app.UIAxes,[app.xMin app.xMax]);
end
end
if ~isempty(app.yMin)
if ~isempty(app.yMax)
ylim(app.UIAxes,[app.yMin app.yMax]);
end
end
then it could be that app.xMax <= app.xMin, or it could be that one or more of app.xMin, app.xMax is non-scalar, or it could be that one or more of app.xMin, app.xMax is NaN.
If you are using str2double() to get the values with empty edit boxes, then you will get NaN(s) because str2double('') returns NaN.
If app.xMin and app.xMax refer to the edit boxes themselves, rather than their values, that would also cause this error. In that case you'd need to get the Value of each edit box and set the limits based on those.

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by