App desginer: how to use the text field (numeric) values as veriables to xlim

2 views (last 30 days)
i have created an app to read an xrd data and produce graphs. i wont the user to be able to control the range of the X axes.
so i have used the numeric field text as an input and thrown it into a veriable
but when i try to use that veriable i get this error
i have attached the code and the file. in order to use the file convert the .txt ending into .xy ending
  5 Comments
Dolev
Dolev on 15 Apr 2023
Edited: Dolev on 15 Apr 2023
if have added the condition to run that part of the code
if mi<ma
but now nothing changes on the axis
dpb
dpb on 15 Apr 2023
Edited: dpb on 17 Apr 2023
Well, what would then expect to have happened if the code doesn't run because your logic bypassed it due to the user improper data?
As Rik suggests, you can
lm=sort([mi ma]); % sort
mi=lm(1); % put back into variables
ma=lm(2);
You really also need the test to be
if mi<=ma
because the call to xlim will fail if they're equal as well; equal is not "strictly increasing"
Looking at your routine above, it appears you've separated the setting of the min and the max from each other; that makes it difficult to keep the two in synch and results in the problem you're now trying to patch up over because it is possible for the user to try to replot (or your code tries automagically on limit change?) when the two limits are not acceptable values.
You should ensure the condition is met when the user leaves either or those two callbacks (unless the max isn't changeable in similar way???). You probably should redesign the user interface so that both limits are set in the same callback and then can test the condition before leaving.
Alternatively, if the user can change only one limit, then before/on exit, test the condition with respect to the other (if change low, then make sure is less than high and vice versa). If the condition isn't satisfied, then either
  1. on leaving provide the warning/information message to the user and either let cancel and change this limit to be acceptable or call the other routine immediately. If do that, then show user what the allowable limit is that will work instead of letting set anything; or
  2. set a flag that the limits bounds are inconsistent and test on that flag before trying to plot and warn user and ask which should fix/edit (or both) to make it be allowable.
I think it makes sense to change the two together in same callback and the values could be adjusted in the other when changes one or at least indicate when during the changing they aren't ok.

Sign in to comment.

Accepted Answer

Rik
Rik on 15 Apr 2023
The reason you don't see anything change when you include the if statement is probably because you didn't include an else statement.
You should either show an error to the user, or sort the XLim (after which you can run the rest of the code normally).
  4 Comments
Dolev
Dolev on 16 Apr 2023
Oh i haven't seen you answer, thank you very much for the detailed explanation, i will try it
Dolev
Dolev on 21 May 2023
figured it out in the end, although in the app designer i gave it a starter value, the code wasnt recognising it and considered it empty, so i have just added the started values at the start of the general code

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!