曲线折叠

2019-04-30 18:16:14 浏览数 (1)

曲线折叠

代码语言:javascript复制
clear ;
close all;
%正常绘图
x=0:0.005:5;
y=exp(-6*x).*sin(x*40)*6 exp(5*x)*5e-11.*sin(x*20);
figure(1)
for i=1:2
  a(i)=subplot(2,1,i);
  title('Before');
  plot(x,y,x,y 2,'o');
  grid on;
  title('Before');
  legend('a','a 2');
  xlim([0 5]);
end
drawnow;

cutout(a(2),1,4,0.2);

%将a(2)的1到4部分折叠为长度0.2的虚线段

title('After');

折叠曲线的函数

代码语言:javascript复制
function cutout(axes_handle,Start,End,Gap)
 xt=axes_handle.XTick;
 xl=axes_handle.XLim;
 p=allchild(axes_handle);
 px={p.XData};
 py={p.YData};
 leg=findobj(axes_handle.Parent,'Tag','legend');
 [leg.AutoUpdate]=deal('off');
 kolor={p.Color};
 hold on;
 for i=1:length(p)
     p(i).XData=px{i}(1:find(px{i}>=Start,1));
     p(i).YData=py{i}(1:find(px{i}>=Start,1));
     x{i}=px{i}(find(px{i}>=End,1):end)-End Start Gap;
     y{i}=py{i}(find(px{i}>=End,1):end);
     pl(i,:)=plot(x{i},y{i},[p(i).XData(end) x{i}(1)],[p(i).YData(end) y{i}(1)],...
 'Color',kolor{i});
     pl(i,2).LineStyle=':';
     pl(i,1).Marker=p(i).Marker;
     pl(i,1).MarkerSize=p(i).MarkerSize;
     pl(i,1).LineWidth=p(i).LineWidth;
 end
 hold off;
 xta=xt(1:find(xt>=Start));
 xta(end)=Start;
 xtb=xt(find(xt>End):end);
 xtb=[End xtb];
 xtL=[xta xtb];
 xt2=[xta xtb-End Start Gap];
 axes_handle.XTick=xt2;
 axes_handle.XTickLabel=xtL;
 axes_handle.XLim=[xl(1) xl(2)-End Start Gap];
end

0 人点赞