Plot line with 2y against single x value

1 view (last 30 days)
Tong D
Tong D on 1 Sep 2020
Commented: Jeremy Perez on 1 Sep 2020
Hi All,
I would like to have these 2 plot aligned with each other. Plotyy give 2 line instead of 1 line.
a is temp, b is altitude, c is pressure.
Code
%%%b is derived using atmospalt(c)
figure(1)
a = [33.8000000000000;28.6000000000000;23.2000000000000;24;23.4000000000000;12.8000000000000;11;-0.900000000000000;-1.30000000000000;-1.30000000000000;-2.70000000000000;-5.10000000000000;-5.70000000000000;-8.10000000000000;-15.1000000000000;-16.3000000000000;-31.7000000000000;-36.7000000000000;-41.7000000000000;-54.1000000000000;-57.3000000000000;-66.7000000000000;-81.9000000000000;-81.3000000000000;-73.9000000000000;-74.1000000000000;-74.3000000000000;-61.3000000000000;-61.5000000000000;-62.3000000000000;-56.3000000000000;-58.3000000000000;-57.5000000000000;-55.3000000000000;-49.7000000000000]
b = [0.297650597021914;0.761966812883245;1.23895437843545;1.36178676400080;1.45730046020214;2.84516670324474;3.01218255324046;4.18101222530275;4.59610330138559;4.63597807547457;4.93373303510833;5.45721197584792;5.57443747451471;6.07466292983455;7.02784947564176;7.18543656870353;9.16395690715245;9.78935726504177;10.3629454664374;11.7840486472932;12.1427963213488;13.6084190399847;15.9922739983573;16.1797246906904;18.0806548063408;18.4416216590731;19.2625955311993;20.3147225362190;20.5761655144013;21.8886585872623;23.0234031230452;23.3723863721426;23.8486475889529;25.1596769921216;25.8892618458144]
c = [978;925;873;860;850;715;700;602;570;567;545;508;500;467;409;400;300;273;250;200;189;150;103;100;74.1000000000000;70;61.5000000000000;52.1000000000000;50;40.7000000000000;34.1000000000000;32.3000000000000;30;24.5000000000000;21.9000000000000]
yyaxis left
ax1(1) = plot(a,b);
yyaxis right
ax2(2) = plot(a,c);
%%%%%
C variable should be placed reversely in secondary y axes. Output shoud looks like the image attached (i.e. just as example).
Cheers
Regards

Answers (2)

Jeremy Perez
Jeremy Perez on 1 Sep 2020
Edited: Jeremy Perez on 1 Sep 2020
  4 Comments
Tong D
Tong D on 1 Sep 2020
no... its not working. This is actually what i am looking for....
Jeremy Perez
Jeremy Perez on 1 Sep 2020
clear all
close all
Works for me. Try cleaning your workspace and figures.

Sign in to comment.


Abdolkarim Mohammadi
Abdolkarim Mohammadi on 1 Sep 2020
Edited: Abdolkarim Mohammadi on 1 Sep 2020
You can use the following command to reverse the order of the elements in the variable c:
c = flip (c);

Tags

Community Treasure Hunt

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

Start Hunting!