1
votes

I have two v_q and v_qb plotted in separate figures, but when I plot them together in the same figure, their values change. Why?

This is the Matlab code (data is from Synopsis software):

v = [ 0.000E+00 2.449E-02 4.898E-02 7.347E-02 9.796E-02 1.224E-01 1.469E-01 1.714E-01 1.959E-01 2.204E-01 2.449E-01 2.694E-01 2.939E-01 3.184E-01 3.429E-01 3.673E-01 3.918E-01 4.163E-01 4.408E-01 4.653E-01 4.898E-01 5.143E-01 5.388E-01 5.633E-01 5.878E-01 6.122E-01 6.367E-01 6.612E-01 6.857E-01 7.102E-01 7.347E-01 7.592E-01 7.837E-01 8.082E-01 8.327E-01 8.571E-01 8.816E-01 9.061E-01 9.306E-01 9.551E-01 9.796E-01 1.004E+00 1.029E+00 1.053E+00 1.078E+00 1.102E+00 1.127E+00 1.151E+00 1.176E+00 1.200E+00];
v_qb = [ 1.200E+00 1.200E+00 1.200E+00 1.200E+00 1.199E+00 1.199E+00 1.198E+00 1.197E+00 1.196E+00 1.194E+00 1.190E+00 1.185E+00 1.178E+00 1.167E+00 1.153E+00 1.134E+00 1.108E+00 1.076E+00 1.034E+00 9.790E-01 9.080E-01 8.408E-01 8.005E-01 7.755E-01 7.578E-01 7.440E-01 7.327E-01 7.231E-01 7.147E-01 7.073E-01 7.006E-01 6.946E-01 6.890E-01 6.839E-01 6.792E-01 6.749E-01 6.709E-01 6.671E-01 6.636E-01 6.603E-01 6.572E-01 6.543E-01 6.515E-01 6.489E-01 6.463E-01 6.438E-01 6.415E-01 6.392E-01 6.370E-01 6.348E-01];
v_q = [ 0.000E+00 2.449E-02 4.898E-02 7.347E-02 9.796E-02 1.224E-01 1.469E-01 1.714E-01 1.959E-01 2.204E-01 2.449E-01 2.694E-01 2.939E-01 3.184E-01 3.429E-01 3.673E-01 3.918E-01 4.163E-01 4.408E-01 4.653E-01 4.898E-01 5.143E-01 5.388E-01 5.633E-01 5.878E-01 6.122E-01 6.367E-01 6.612E-01 6.857E-01 7.102E-01 7.347E-01 7.592E-01 7.837E-01 8.082E-01 8.327E-01 8.571E-01 8.816E-01 9.061E-01 9.306E-01 9.551E-01 9.796E-01 1.004E+00 1.029E+00 1.053E+00 1.078E+00 1.102E+00 1.127E+00 1.151E+00 1.176E+00 1.200E+00];

%plotting together
figure(1) 
plot(v_qb,v_q)
hold on
plot(v,v_qb)

%plotting separately
figure(2) 
plot(v_qb,v_q)
figure(3) 
plot(v,v_qb)
2
How are you plotting them in separate plots? Please edit your question so that others can try to replicate your issue. - horchler
I revised the code per your instruction. Thanks - Aliyar Attaran
Works fine for me.The x-axis of figure(2) is different from figure(1) and the y-axis of figure(3) is different from figure(1). This is just so both plots can fit together. As per the documentation, hold does not affect axis auto-ranging. Use axis if you want to customize the axis values. - horchler

2 Answers

1
votes

This is expected behavior. The x-axis of figure(2) and the y-axis of figure(3) are different from those in figure(1) so the full ranges of both plots can fit together. As per the documentation and help, hold does not affect axis auto-ranging:

MATLABĀ® adjusts axes limits, tick marks, and tick labels to display the full range of data.

Use the axis function if you want to customize the axis values. In particular, you might use axis manual to prevent the axis ranges from changing after your first call to plot:

figure(1) 
plot(v_qb,v_q)
hold on
axis manual
plot(v,v_qb)

using axis manual

This of course will clip the left side (0 to 0.6) of the second call to plot. Not sure exactly what you want so please play around with the options.

1
votes

This is the solution:

% Matlab M-file converted by [Custom WaveView] saved 08:19:49 Wed Feb 22 2017
v= [ 0.000E+00 2.449E-02 4.898E-02 7.347E-02 9.796E-02 1.224E-01 1.469E-01 1.714E-01 1.959E-01 2.204E-01 2.449E-01 2.694E-01 2.939E-01 3.184E-01 3.429E-01 3.673E-01 3.918E-01 4.163E-01 4.408E-01 4.653E-01 4.898E-01 5.143E-01 5.388E-01 5.633E-01 5.878E-01 6.122E-01 6.367E-01 6.612E-01 6.857E-01 7.102E-01 7.347E-01 7.592E-01 7.837E-01 8.082E-01 8.327E-01 8.571E-01 8.816E-01 9.061E-01 9.306E-01 9.551E-01 9.796E-01 1.004E+00 1.029E+00 1.053E+00 1.078E+00 1.102E+00 1.127E+00 1.151E+00 1.176E+00 1.200E+00];
v_qb = [ 1.197E+00 1.196E+00 1.194E+00 1.190E+00 1.185E+00 1.175E+00 1.161E+00 1.139E+00 1.105E+00 1.054E+00 9.774E-01 8.640E-01 7.241E-01 6.262E-01 5.471E-01 4.680E-01 3.832E-01 2.921E-01 1.988E-01 1.248E-01 8.988E-02 7.198E-02 6.078E-02 5.303E-02 4.734E-02 4.299E-02 3.957E-02 3.680E-02 3.453E-02 3.263E-02 3.101E-02 2.963E-02 2.843E-02 2.739E-02 2.647E-02 2.566E-02 2.495E-02 2.433E-02 2.377E-02 2.328E-02 2.285E-02 2.247E-02 2.213E-02 2.183E-02 2.155E-02 2.131E-02 2.108E-02 2.088E-02 2.069E-02 2.052E-02];
v_q = [ 0.000E+00 2.449E-02 4.898E-02 7.347E-02 9.796E-02 1.224E-01 1.469E-01 1.714E-01 1.959E-01 2.204E-01 2.449E-01 2.694E-01 2.939E-01 3.184E-01 3.429E-01 3.673E-01 3.918E-01 4.163E-01 4.408E-01 4.653E-01 4.898E-01 5.143E-01 5.388E-01 5.633E-01 5.878E-01 6.122E-01 6.367E-01 6.612E-01 6.857E-01 7.102E-01 7.347E-01 7.592E-01 7.837E-01 8.082E-01 8.327E-01 8.571E-01 8.816E-01 9.061E-01 9.306E-01 9.551E-01 9.796E-01 1.004E+00 1.029E+00 1.053E+00 1.078E+00 1.102E+00 1.127E+00 1.151E+00 1.176E+00 1.200E+00];
%plotting together
figure(2) 
plot(v_qb,v_q)
hold on
plot(v,v_qb)
hold on
grid on      
x = 0:1.2/10:1.2;

figure (3)
for b=-2:0.5:2
    plot(x, x+b);
    hold on
end
hold on
plot(v_qb,v_q)
hold on
plot(v,v_qb)