How to link uialert to my App Designer UI figure?
조회 수: 48(최근 30일)
표시 이전 댓글
I recently took over a MATLAB project of a former colleague and is still learning how to write MATLAB code correctly. I would like to change working code that currently uses msgbox to now rather make use of uialert(). I can however not find a way to link the UIFigure of my app to the uialert function. My understanding is that the arguments should be as follows: uialert(uifigure,message,title). My problem seems to be with the uifigure argument.
The uialert Help indicates that the uifigure must be created with the uifigure function. When I use the following code I do get a new uifigure and the alert message appears in front of it as expected.
f = uifigure;
uialert(f,'Test','warning');
I do however want the alert message to appear in front of the App Designer UIFigure rather than a newly created figure. I found code here on the forum that identifies the name of my App Designer figure:
hFigs = findall(groot, 'Type', 'figure')
hFigs = Figure (VTT) with properties:
Number: []
Name: 'VTT'
I tried several ways to try to refer to the name of my App Designer figure but none of them worked. Below are two examples of what I tried.
uialert('VTT','Test','warning');
uialert(hFigs.Name,'Test','warning');
I got the following error with both lines of code:
Error using uialert (line 35)
Invalid or deleted figure handle. First argument must be a valid figure handle
I might be using the wrong terminology but I can not find any answers in this forum that explained to me how I can link uialert() to appear in front of the the App Designer UIFigure.
답변(2개)
Eduardo Gil
2019년 12월 9일
I am having the same problem. My code is very straightforward - just an error message to the user in case "end date" is less than "start date".
% error message in case end_date <= start_date
d=app.UIAxes;
if end_date <= start_date
uialert(d,'Plot End Date must be greater than Plot Start Date!','Invalid Input');
end
I get the following error:
Error using uialert (line 42)
Invalid or deleted figure handle. First argument must be a valid figure handle
Error in Weather_Chart/refreshplot (line 214)
plot_data(app,xdata,ydata,zdata,zdata_backcast,min_date,max_date);
Error in Weather_Chart/DatePicker_2ValueChanged (line 266)
refreshplot(app)
댓글 수: 0
Eduardo Gil
2019년 12월 10일
Found the aswer. It's not app.UIAxes, but rather the name for the entire figure (in my case: Load_Analysis matlab.ui.Figure). A bit of trial and error:
uialert(App.Load_Analysis,'Plot End Date must be greater than Plot Start Date!','Invalid Input');
댓글 수: 2
참고 항목
범주
Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!