Apply changes to ALL UIAxes in AppDesigner?
9 views (last 30 days)
Show older comments
I need to make an app in Appdesigner which will contain 19 axes. I want to make changes to the axes according to:
function startupFcn(app)
yyaxis(app.UIAxes2,'right')
app.UIAxes2.YLabel.String='NAME for your RIGHT Y Axis';
app.UIAxes2.YLim = [0 25];
app.UIAxes2.YColor = [1 0 0]; % font colour
yyaxis(app.UIAxes2,'left')
app.UIAxes2.YLabel.String='NAME for your LEFT Y Axis';
app.UIAxes2.YLim = [0 100];
app.UIAxes2.Color = [1 1 0.8]; % plot box colour
app.UIAxes2.XGrid = 'on';
app.UIAxes2.YGrid = 'on';
end
But since the axes are named "UIAxes", "UIAxes2", "UIAxes3" and so on, I need to write the code above several times for each UIAxes, which is tedious work. Is there any way to run a for command that goes through all the axes? Just using "for" and then strcat() does not seem to work.
Thank you for your help!
0 Comments
Answers (1)
Adam Danz
on 12 Mar 2019
Edited: Adam Danz
on 25 Mar 2019
Option 1: optimize one of your axes and then copy it.
If you haven't created the 19 axes in your app yet, create the first one, perfect it, and then just copy/paste it as many times as you need. Some modifications (such as the right side y axis) can't be made in design mode and you'll have to use option 2 for those modifications but the more changes you can make at this level, the better.
Option 2: write a function and send all axis handles into the function.
Start a new function in your app where the first input is app (required) and the 2nd input is 'axisHandle'. Move all of your parameter adjustments to that function and apply them all to "axisHandle". Then in your startup fcn, you'll just send each axis handle into the function.
function startupFcn(app)
fixAxes(app, app.UIAxes)
fixAxes(app, app.UIAxes2)
fixAxes(app, app.UIAxes3)
fixAxes(app, app.UIAxes4)
end
function fixAxes(app, axisHandle)
%ignore erroneous warnings to specify axis handles as first argument
yyaxis(axisHandle,'right')
axisHandle.YLabel.String='NAME for your RIGHT Y Axis';
axisHandle.YLim = [0 25];
axisHandle.YColor = [1 0 0]; % font colour
yyaxis(axisHandle,'left')
axisHandle.YLabel.String='NAME for your LEFT Y Axis';
axisHandle.YLim = [0 100];
axisHandle.Color = [1 1 0.8]; % plot box colour
axisHandle.XGrid = 'on';
axisHandle.YGrid = 'on';
end
Not tested
Option 2b: use a loop in option 2
function startupFcn(app)
allAxes = [app.UIAxes, app.UIAxes2, app.UIAxes3, app.UIAxes4];
for i = 1:length(allAxes)
fixAxes(app, allAxes(i))
end
end
% or the loop could be within the fixAxes() function and you could send in 'allAxes'.
4 Comments
Adam Danz
on 14 Mar 2019
Edited: Adam Danz
on 25 Mar 2019
You can pan/zoom through axes but that's not possible to do on a figure as far as I know. The better solution would be to set the figure size to your monitor size.
figure('units','normalized','outerposition',[0 0 1 1])
But with 19 subplot, that will probably reduce the size of the subplot axes so much that their utility would suffer. It would be nice for matlab to build a scroll bar on figures, though.
I suggest breaking your plots up into multiple figures.
See Also
Categories
Find more on Title 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!