Borrar filtros
Borrar filtros

Apply changes to ALL UIAxes in AppDesigner?

6 visualizaciones (últimos 30 días)
Henry Eriksson
Henry Eriksson el 12 de Mzo. de 2019
Editada: Adam Danz el 12 de Dic. de 2019
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!

Respuestas (1)

Adam Danz
Adam Danz el 12 de Mzo. de 2019
Editada: Adam Danz el 25 de Mzo. de 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 comentarios
Henry Eriksson
Henry Eriksson el 13 de Mzo. de 2019
Thanks!!
By the way. The resulting figure containing all 19 plots is a lot bigger than my screen. I would like to both pan and zoom in the figure. Is this possible? I have been trying to find a way to add a scroll function to the figure but failed so far. Do you know how to fix this? It would be nice to be able to zoom into the figure to a particular plot, and then also be able to furhter zoom into that plot. I hope I am making some sense.
Adam Danz
Adam Danz el 14 de Mzo. de 2019
Editada: Adam Danz el 25 de Mzo. de 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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by