Saveas figure (UIAxes) from app designer to a specific folder left and right plots

I'm traying to save a figure (UIAxes) with left and right axis from app designer to a specific foder by using the following code existing in this link:
Then i have this error : "Undefined function 'copyUIAxes' for input arguments of type 'matlab.ui.control.UIAxes' "
I'm using matlab 2016b.
% Create yyaxis plot within uiaxes
fig = uifigure();
ax = uiaxes(fig);
yyaxis(ax, 'left')
plot(ax, 1:5, rand(1,5), '-')
ylabel(ax, 'left')
yyaxis(ax, 'right')
plot(ax, 1:.2:5, rand(1,21), 'o')
ylabel(ax, 'right')
xlabel(ax, 'x axis')
title(ax, 'Title')
% Copy left and right axes to the same figure
newFig = figure;
yyaxis(ax, 'left')
axLeft = copyUIAxes(ax, newFig);
yyaxis(ax, 'right')
axRight = copyUIAxes(ax, newFig);
% Make some changes to the right axes
axRight.axes.Color = 'none'; % make transparent
axRight.axes.XTick = []; % remove duplicate x-ticks
axRight.axes.XLabel = []; % remove duplicate x-label
axRight.axes.Title = []; % remove duplicate title

 Respuesta aceptada

Adam Danz
Adam Danz el 4 de Jun. de 2021
Editada: Adam Danz el 6 de Jun. de 2021
You must be referring to this answer which contains a link to the function on the file exchange.
Make sure the file is on your Matlab path. Also make sure you're using version 4.0.0 or later to copy yyaxis plots.
Update
After viewing your code, I see where you're using the function incorrectly. You're copying the left and right axes separately. copyUIAxes copies both the left and right axes. So you're actually producing two copies on the same figure.
Here's the correction
% Create yyaxis plot within uiaxes
fig = uifigure();
ax = uiaxes(fig);
yyaxis(ax, 'left')
plot(ax, 1:5, rand(1,5), '-')
ylabel(ax, 'left')
yyaxis(ax, 'right')
plot(ax, 1:.2:5, rand(1,21), 'o')
ylabel(ax, 'right')
xlabel(ax, 'x axis')
title(ax, 'Title')
% Copy left and right axes to the same figure
newFig = figure;
axLeft = copyUIAxes(ax, newFig);

7 comentarios

amakoba yim
amakoba yim el 6 de Jun. de 2021
Editada: Adam Danz el 6 de Jun. de 2021
Thank's for your answer, it's work, but the plot and axis are duplicated several times on the copied figure with the "copyUIAxes" function, as shown in the following figure :
That does not occur when I test the function using the most recent version (4.0.1, or 4.0.0). It loo
Make sure your code is following this demo or explain how your workflow differs.
data1 = [1 3 4 5; .6 .45 .85 .7]; % [x;y] coordinates of blue line
data2 = [rand(1,20)*4+1; rand(1,20)]; %[x;y] coordinates of orange markers
uif = uifigure();
ax = uiaxes(uif);
yyaxis(ax,'left')
plot(ax, data1(1,:), data1(2,:), '-')
yyaxis(ax,'right')
plot(ax, data2(1,:), data2(2,:), 'o')
fig = figure();
copyUIAxes(ax,fig)
Right-click image and open in new tab to see full size.
If that didn't solve the problem please provide the following as at attachment so I can determine if this is user-error or a use-case that isn't function with the current version of copyUIAxes.
  • A minimal version of the code you're using to copy the axes.
  • A fig file containing the figure you're copying.
That's not what I need to reproduce the problem. You attached the copyUIAxes code which I already have and you attached the figure containing the copied axes.
What I need is the code you wrote that calls copyUIAxes and the original figure that you're copying.
But first, see my edited comment above to make sure you're using the function correctly.
@amakoba yim Sorry, I just noticed that you already provided the code in your question. Thank you, I didn't see it previously.
I'll update my answer to show what you're doing incorrectly.
It works well.
I'm sorry I didn't see your answer.
Thank you very much for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Programmatically en Centro de ayuda y File Exchange.

Preguntada:

el 3 de Jun. de 2021

Comentada:

el 8 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by