App desginer: how to use the text field (numeric) values as veriables to xlim
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
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
- 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
- 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
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).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!