# How to plot a curve between 2 data sets

4 views (last 30 days)
Opariuc Andrei on 25 Oct 2021
Commented: Opariuc Andrei on 25 Oct 2021
%% input data
P1=[2.3;3.9;3.5;4.8;5.5;6.3;7.4];
P2=[4.8;5.7;6.5;7.8;9.2;10.5;11.8];
D=[78;65;57;52;46;32;27];
%%
Dp=P2-P1;
Q=0.24*D;
%% plot
subplot(3,1,1);plot(Dp,'r*');grid on;axis tight;
subplot(3,1,2);plot(Q,'b*');grid on;axis tight;
subplot(3,1,3);plot(Dp,'r*');hold on;plot(Q,'b*');hold off;grid on;axis tight;legend('Dp','Q');
How do i plot a curve between Dp and Q ? in the third subplot

KSSV on 25 Oct 2021
P1=[2.3;3.9;3.5;4.8;5.5;6.3;7.4];
P2=[4.8;5.7;6.5;7.8;9.2;10.5;11.8];
D=[78;65;57;52;46;32;27];
%%
Dp=P2-P1;
Q=0.24*D;
%
x = [1:length(Dp) flip(1:length(Q))] ;
y = [Dp; flip(Q)] ;
plot(x,y)

Chunru on 25 Oct 2021
Do you mean Dp vs Q?
%% input data
P1=[2.3;3.9;3.5;4.8;5.5;6.3;7.4];
P2=[4.8;5.7;6.5;7.8;9.2;10.5;11.8];
D=[78;65;57;52;46;32;27];
%%
Dp=P2-P1;
Q=0.24*D;
%% plot
subplot(3,1,1);plot(Dp,'r*');grid on;axis tight;
subplot(3,1,2);plot(Q,'b*');grid on;axis tight;
%subplot(3,1,3);plot(Dp,'r*');hold on;plot(Q,'b*');hold off;grid on;axis tight;legend('Dp','Q');
subplot(3,1,3);plot(Dp, Q, 'r*');grid on;axis tight;xlabel('Dp'); ylabel('Q')
Opariuc Andrei on 25 Oct 2021
a random curve between Dp and Q but withuot the curve connecting with any of the data ,Dp and Q have to be displayed as points as in the third subplot in my original code.

R2020a

### Community Treasure Hunt

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

Start Hunting!