How to workaround the plotyy copyobj error?
1 view (last 30 days)
Show older comments
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
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.
Accepted Answer
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.
More Answers (0)
See Also
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!