How to workaround the plotyy copyobj error?

조회 수: 4 (최근 30일)
sejo
sejo 2014년 10월 2일
편집: sejo 2014년 10월 17일
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
dpb
dpb 2014년 10월 2일
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 2014년 10월 2일
Thx, for your infos. I run R2014a so there the problem still remains... Lets see what the support suggests...

댓글을 달려면 로그인하십시오.

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 10월 2일
편집: Joseph Cheng 2014년 10월 2일
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
sejo
sejo 2014년 10월 2일
Thx for your workaround. I´ll try if that is working for me...
sejo
sejo 2014년 10월 17일
편집: sejo 2014년 10월 17일
Finally managed to do this task. Used the workaround of plotting the data again in the new figure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by