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

2 vues (au cours des 30 derniers jours)
Dolev
Dolev le 14 Avr 2023
Commenté : Dolev le 21 Mai 2023
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 commentaires
Dolev
Dolev le 15 Avr 2023
Modifié(e) : Dolev le 15 Avr 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 le 15 Avr 2023
Modifié(e) : dpb le 17 Avr 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.

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 15 Avr 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 commentaires
Dolev
Dolev le 16 Avr 2023
Oh i haven't seen you answer, thank you very much for the detailed explanation, i will try it
Dolev
Dolev le 21 Mai 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

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by