Plot line with 2y against single x value
Afficher commentaires plus anciens
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
Réponses (2)
Jeremy Perez
le 1 Sep 2020
Modifié(e) : Jeremy Perez
le 1 Sep 2020
0 votes
Hi,
Read this:
Use ylim
Also in your picture you have a semilog y plot
4 commentaires
Tong D
le 1 Sep 2020
Jeremy Perez
le 1 Sep 2020
Modifié(e) : Jeremy Perez
le 1 Sep 2020
Try this:
yyaxis left
ax1(1) = plot(a,b);
yyaxis right;
ax2(2) = plot(a,c);
ylim([-100.3437 41.2455])
Use the hand tool (or any other tool) to offset your curve
Use ylim to get the display the values.
Reinput them in your code.
Tong D
le 1 Sep 2020
Jeremy Perez
le 1 Sep 2020
clear all
close all

Works for me. Try cleaning your workspace and figures.
Abdolkarim Mohammadi
le 1 Sep 2020
Modifié(e) : Abdolkarim Mohammadi
le 1 Sep 2020
You can use the following command to reverse the order of the elements in the variable c:
c = flip (c);
1 commentaire
Tong D
le 1 Sep 2020
Catégories
En savoir plus sur Grid Lines, Tick Values, and Labels dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
