App Designer keeps telling me to "specify a uiaxes handle as first argument" when the first argument is a uiaxes handle

When I push a button I want to create blank axes and then plot data on them. In the push button callback this is part of my code
ax1 = uiaxes(app.PlotsTab, 'Position', [x y w h]);
plot(ax1, app.P2x, app.P2y)
This seems to work as expected however App Designer tells me to "specify UIaxes handle as first argument." I am wondering if I have overlooked something or if my syntax is incorrect. Any information is appreciated. Thanks in advance.

2 Comments

Set a breakpoint on that first line of your code then run your code. When you reach that breakpoint, before that line that tries to create the uiaxes runs, execute this command and show what it returns.
class(app.PlotsTab)
When I set the breakpoint and execute the following command in the command window this is what it returns
class(app.PlotsTab)
ans =
matlab.ui.container.Tab
Also, if I run the following command after the axes is created it returns
class(ax1)
ans =
matlab.ui.control.UIaxes
I assumed that meant ax1 was indeed the UIaxes handle

Sign in to comment.

 Accepted Answer

Tyler, it sounds like the code is executing properly, but the message you're referring to is not a run-time error, but instead a programming alert popping up inside the editor. If this is the case, you can safely ignore the alert.
It is interpreting your syntax as being incorrect because it expects the first argument to PLOT to be of the form:
app.YourAxesComponent
This is because in the vast majority of use cases, an axes handle needs to be stored as part of the app so it can be easily accessed later within a callback. In your specific case, you can store the UIAxes handle in your app by creating a property and setting it to the UIAxes handle upon creating it. To access it, you would need to specify app., which is analogous to doing handle. in the GUIDE world. (Since app. was a common programming oversight, the alert was added to catch the issue early for users.)
If you prefer to not store the UIAxes handle as part of your app, you can avoid seeing the alert by disabling the "Enable app coding alerts" checkbox in the Editor tab. This however will hide all alerts, so take that into consideration.

3 Comments

I'll put a part of the code with similar issue, where one command issues the warning and the other does not. Maybe a bug or something here? R2020a
ax2 = app.UIAxesBlankCurves;
ax2.XLabel.String = 'x(mm)';
ax2.YLabel.String = 'y(mm)';
axis (ax2, 'equal'); % No warning here
ax2.Title.String = 'Title'
legend(ax2, 'location', 'northeastoutside'); % Specify a UIAxes handle as first argument. Warning here
If I write it this way, it won't give the warning
legend(app.UIAxesBlankCurves, 'location', 'northeastoutside');
Is there a way to suppress these warnings in appDesigner using the %#<ID> notation? If so, how do I determine what the correct Message ID is?
I have the same problem. The method of using "app.ax" does not work for me. It keeps warning me to specify an uiaxes handle as the first argument:
hfg = uifigure();
hfg.AutoResizeChildren = 'off';
app.ax1 = subplot(2,1,1,'Parent', hfg);
plot(app.ax1, t, h);
I am using R2019b.

Sign in to comment.

More Answers (1)

I still have the warning. what is wrong with the code
properties (Access = public)
% für Plots die Achsen name als Property definieren
ax;
ax1;
ax2;
end
p1fig=uifigure('Name','plot1','Color','white');
p1fig.ToolBar='none';
p1fig.MenuBar='none';
app.ax=uiaxes(p1fig,'XLim',[x_min_axis,x_max_axis],'YLim', [y_min_axis,y_max_axis],'XGrid','on',"YGrid","on");
app.ax.Interactions=[];
app.ax.Toolbar.Visible='off';
app.ax.Title.String=app.DIA1_TXT(1,1);
app.ax.XLabel.String=app.DIA1_TXT(1,2);
app.ax.YLabel.String=app.DIA1_TXT(1,3);
% call Plot
plot(app.ax,rt_ScopeData1(:,1), rt_ScopeData1(:,2:size(rt_ScopeData1,2)),'-','LineWidth',2);
legend(app.ax,app.LTEXT1, 'Location','southeast');
In the plot and Legend command there still comes the warning
"Specify a UIAxes handle as first argument"
Iwould like to undrerstand why this warning still comes.

Community Treasure Hunt

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

Start Hunting!