zoomed plot in the same figure

17 ビュー (過去 30 日間)
christian robledo
christian robledo 2017 年 7 月 17 日
コメント済み: Jan 2017 年 7 月 17 日
Hello i am trying to do a zoomed plot in the same figure using the plotyy function... Ive tried to play around with the explanations given here https://de.mathworks.com/matlabcentral/answers/33779-zooming-a-portion-of-figure-in-a-figure but i couldnt make it so far... The section im interested in is between the graphs plotted by (x5,y5,x6,y6) at x between 0.6 and 0.8 and y between 0.18 and 0.2.... If someboy could give me a hint i would be really greatfull. The version im using is R2012a..
Thank you very much
%Bed profile of Run 20°C
BP_num_6s_fv=xlsread('Results.xlsx','t=6s',' M3:N203');
%Velocities of Run 20°C and Run 5°C
velo6s_20=xlsread('Results.xlsx','Velocity',' I3:J203');
velo6s_5=xlsread('Results.xlsx','Velocity',' L3:M203');
% Bed profile At t=6s
x1 = BP_num_6s_fv(:,1); y1= BP_num_6s_fv(:,2);
% Velocity Run 20°C and 5°C
x5 = velo6s_20(:,1); y5 =velo6s_20(:,2);
x6 = velo6s_5(:,1); y6 =velo6s_5(:,2);
figure (1)
hold on
[ax,h1,h2]=plotyy(x1,y1,x5,y5)
h(3) = line(x6,y6, 'Parent', ax(2));
set(h(3),'Color','r')
% create a new pair of axes inside current figure
axes('position',[.65 .175 .25 .25])
box on % put box around new pair of axes
indexOfInterest = (x5 < 0.8) & (x5 >0.6); % range of t near perturbation
a=x5;
plot(a(indexOfInterest),g(indexOfInterest)) % plot on new axes
axis tight
  4 件のコメント
Adam
Adam 2017 年 7 月 17 日
Would it not just be easier to set the XLim and YLim properties to the desired range?
christian robledo
christian robledo 2017 年 7 月 17 日
編集済み: christian robledo 2017 年 7 月 17 日
maybe.. im just kind of starting with matlab and struggling with the basics.. could you maybe show me how i can implement it in my code? that would be awesome!
Ive tried someting like this but it just gives me like a straight line
figure (1)
hold on
[ax,h1,h2]=plotyy(x1,y1,x5,y5)
h(3) = line(x6,y6, 'Parent', ax(2));
set(h(3),'Color','r')
% create a new pair of axes inside current figure
axes('position',[.65 .175 .25 .25])
box on % put box around new pair of axes
indexOfInterest1 = (x5 < 0.8) & (x5 >0.6); % range of t near perturbation
indexOfInterest2 = (y6<0.2) & (y6>0.18);
plot(indexOfInterest1,indexOfInterest2 )
axis tight

サインインしてコメントする。

採用された回答

Jan
Jan 2017 年 7 月 17 日
編集済み: Jan 2017 年 7 月 17 日
Do you mean:
indexOfInterest = (x5 < 0.8) & (x5 >0.6); % range of t near perturbation
plot(x5(indexOfInterest), y6(indexOfInterest));
There are some zoom tools in the FileExchaage:
  2 件のコメント
christian robledo
christian robledo 2017 年 7 月 17 日
Hello Jan yes thanks, i think now it plots the right section.. the only thing is that it only plots one graph... In the figure were i denoted area of interest there are actually two graphs very very close to each other (x5,y5 and x6,y6).. thats why i wanted to have that zoom in plot... is there a way to make them both visible? Thanks again for your answer
Jan
Jan 2017 年 7 月 17 日
If you know the code to plot one line, use it to draw both lines:
axes('position',[.65 .175 .25 .25], 'NextPlot', 'add')
indexOfInterest1 = (x5 < 0.8) & (x5 > 0.6);
indexOfInterest2 = (x6 < 0.8) & (x6 > 0.6);
plot(x5(indexOfInterest1), y5(indexOfInterest1));
plot(x6(indexOfInterest2), y6(indexOfInterest2));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by