How to workaround the plotyy copyobj error?

1 view (last 30 days)
Hy, I have the same question like this question. But unfortunately the linke for the workarond is removed.
Can anyone help me how to copy both axes of the ployy to another figure?
  2 Comments
dpb
dpb on 2 Oct 2014
Seems TMW has removed everything prior to ca. R14 from the bug report search engine. Unfortunately, the symptoms seem to remain here w/ R2012b; I presume since the original posting dates from 2004 they probably also are still around in most recent releases as well...
Which release are you running and do you have support? Looks like an official bug report is due again to re-raise the issue if others can duplicate the problem still.
Maybe Steven L will stumble by and by dint of being inside TMW can resurrect the previous workaround or recalls enough to regenerate it.
sejo
sejo on 2 Oct 2014
Thx, for your infos. I run R2014a so there the problem still remains... Lets see what the support suggests...

Sign in to comment.

Accepted Answer

Joseph Cheng
Joseph Cheng on 2 Oct 2014
Edited: Joseph Cheng on 2 Oct 2014
This is a bit lengthy but you can try something like this where you save the data in userdata if the original data is nolonger available. then copy each parameter as such.
%generate some plots
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
%create new fig
figh1 = figure;
plotyy1 = plotyy(x,y1,x,y2);
%save the data in userData incase you don't have it for the new plot
set(plotyy1(1),'UserData',[x;y1]);
set(plotyy1(2),'UserData',[x;y2]);
set(plotyy1(1),'Ylim',[-500 500]);
set(plotyy1(2),'Ylim',[0 1]);
%create figure to copy to
figh2 = figure;
%reclaim the data if lost but figure is still there
reclmXY1 = get(plotyy1(1),'userData');
reclmXY2 = get(plotyy1(2),'userData');
%plot the two as a new yy
plotyy2= plotyy(reclmXY1(1,:),reclmXY1(2,:),reclmXY2(1,:),reclmXY2(2,:));
%get the parameters names for the axes
param = fieldnames(get(plotyy1(1)));
for ind = 1:2 %loop through the two plots
for jind=1:length(param)
try,
%just for debug to see what properties are set
disp(param(jind))
temp = get(plotyy1(ind),param(jind)); %can be inside the set()
if ~strcmp(param(jind),'Parent'); %skip designating parent
set(plotyy2(ind),param(jind),temp) %copy axes param
end
end
end
end
There could be an easier way to copy/set all the parameters except for the parent for each handle object but cannot come up with it at the moment.
  2 Comments
sejo
sejo on 2 Oct 2014
Thx for your workaround. I´ll try if that is working for me...
sejo
sejo on 17 Oct 2014
Edited: sejo on 17 Oct 2014
Finally managed to do this task. Used the workaround of plotting the data again in the new figure.

Sign in to comment.

More Answers (0)

Categories

Find more on Two y-axis 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!