How to link uialert to my App Designer UI figure?

조회 수: 48(최근 30일)
Hannes Truter
Hannes Truter 2019년 8월 15일
댓글: Frederick Breidt 2020년 7월 21일
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.
  댓글 수: 10
Hannes Truter
Hannes Truter 2019년 8월 20일
Everything you wrote above seems logical but the reality does not seem to match it in my app. I can not spend any more time on this. I'll just make peace with the fact that uialert can not work with the GUI of my app. I can not find a single example on any of the forums I looked at where anybody successfully implemented uialert with their uifigure. I'll just keep on using the message box.

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

답변(2개)

Eduardo Gil
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)

Eduardo Gil
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
Frederick Breidt
Frederick Breidt 2020년 7월 21일
Greetings,
I found it, try: app.UIFigure

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

범주

Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by