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

조회 수: 2 (최근 30일)
Dolev
Dolev 2023년 4월 14일
댓글: Dolev 2023년 5월 21일
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
Dolev
Dolev 2023년 4월 15일
편집: Dolev 2023년 4월 15일
if have added the condition to run that part of the code
if mi<ma
but now nothing changes on the axis
dpb
dpb 2023년 4월 15일
편집: dpb 2023년 4월 17일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2023년 4월 15일
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
Dolev
Dolev 2023년 4월 16일
Oh i haven't seen you answer, thank you very much for the detailed explanation, i will try it
Dolev
Dolev 2023년 5월 21일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by