
Scaling Right y-axis
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I'm trying to make a graph simulating some concentrations through a reactor, and want to graph another property along a secondary y-axis. The domain for that property is from 0 to 1 and I want to scale that axis accordingly (right now it automatically scales from 0 to 0.8). After a couple searches I found a possible solution that I've bolded in my code, but when I run it, my plot has the original 0 to 0.8 right axis overlapping the new 0 to 1 right axis. How do I fix this?
clc; clear
global k C0
k = zeros(3,1); % initial conditions/constants
k(1) = 0.25; k(2) = 0.1; k(3) = 5;
C0 = zeros(6,1); % A, B, C, R, X
C0(1) = 1.5; C0(2) = 2; C0(3:end) = 0; % Ca0, Cb0, Cc0, Cd0, Ce0, Cf0
Vmax = 50; v0 = 10; % L; L/min
[tau,C] = ode45(@firstorder,[0 5],[C0(1) C0(2) C0(3) C0(4) C0(5) C0(6)]); % the man o the hour
X = (C0(1)-C(:,1))/C0(1);
[Ca_max,iMaxA] = max(C(:,1));
[Cb_max,iMaxB] = max(C(:,2));
[Cc_max,iMaxC] = max(C(:,3));
[Cd_max,iMaxD] = max(C(:,4));
[Ce_max,iMaxE] = max(C(:,5));
[Cf_max,iMaxF] = max(C(:,6));
V = tau*v0;
plotyy(V,C(:,1),V,X); hold on; plot(V,C(:,2)); plot(V,C(:,3));
plot(V,C(:,4)); plot(V,C(:,5)); plot(V,C(:,6));
% makin' it purdy
yyaxis right
ylim([0 1]);
xlabel('Volume of Reactor (L)');
ylabel('Concentration (M)');
legend('C_A','C_B','C_C','C_D','C_E','C_F','X_A');
plot(V(iMaxA),C(iMaxA,1),'o','HandleVisibility','off'); plot(V(iMaxB),C(iMaxB,2),'o','HandleVisibility','off'); plot(V(iMaxC),C(iMaxC,3),'o','HandleVisibility','off');
plot(V(iMaxD),C(iMaxD,4),'o','HandleVisibility','off'); plot(V(iMaxE),C(iMaxE,5),'o','HandleVisibility','off'); plot(V(iMaxF),C(iMaxF,6),'o','HandleVisibility','off');
function dC = firstorder(tau,C) % my fancy-shmancy differential equations
global k
dC = zeros(6,1);
dC(1) = -k(1)*C(1)*C(2)^2 - 3*k(2)*C(1)*C(4); % dCa/dT
dC(2) = -2*k(1)*C(1)*C(2)^2 - k(3)*C(2)*C(3)^2; % dCb/dT
dC(3) = k(1)*C(1)*C(2)^2 + k(2)*C(1)*C(4) - 2*k(3)*C(2)*C(3)^2; % dCc/dT
dC(4) = k(1)*C(1)*C(2)^2 - 2*k(2)*C(1)*C(4) + k(3)*C(2)*C(3)^2; % dCd/dT
dC(5) = k(2)*C(1)*C(4); % dCe/dT
dC(6) = k(3)*C(2)*C(3)^2; % dCf/dT
end
Thank you!
0 commentaires
Réponses (1)
Mehmed Saad
le 23 Avr 2020
Modifié(e) : Mehmed Saad
le 23 Avr 2020
Remove ylim from line 28 and insert it at the end of the code

It is recommended to Remove the ployy part from your code
use
yyaxis left
and
yyaxis right
for plotting on left and right side respectively
0 commentaires
Voir également
Catégories
En savoir plus sur Assembly dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!