Legend function shows wrong colors.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Oguz Munib Esen
le 11 Jan 2021
Modifié(e) : Oguz Munib Esen
le 11 Jan 2021
Hi, i want to plot my curves with respect to time. However legend function assigns wrong color values to wrong colors. That is, it does not name them with the order gave to it.
Thanks for the help!
clc
clear all
close all
k_a=1/8;
k_b=0.2;
k_c=4;
k_g=0.1;
k_w=0.2;
h=0.2;
ti=0;
tf=100;
T=ti:h:tf;
S=zeros(length(T));
E=zeros(length(T));
I=zeros(length(T));
M=zeros(length(T));
R=zeros(length(T));
%%Some code.
plot(T,S)
hold on
plot(T,E)
hold on
plot(T,I)
hold on
plot(T,M)
hold on
plot(T,R)
hold on
legend('Suceptibles','Exposed','Infected','Medicaly Semptomatic','Recovered')
2 commentaires
Adam
le 11 Jan 2021
It would help if you posted the result of doing all that so we can see what the legend looks like. It seems fine to me when I run it.
Réponse acceptée
Walter Roberson
le 11 Jan 2021
zeros(length(T)) is the same as zeros(length(T), length(T)) which is a 2D array.
k_a=1/8;
k_b=0.2;
k_c=4;
k_g=0.1;
k_w=0.2;
h=0.2;
ti=0;
tf=100;
T=ti:h:tf;
S=zeros(size(T));
E=zeros(size(T));
I=zeros(size(T));
M=zeros(size(T));
R=zeros(size(T));
S(1)=10000;
E(1)=10;
I(1)=0;
M(1)=0;
R(1)=0;
for i=1:length(T)-1
S(i+1)=S(i)-h*((k_c*k_b*I(i)*S(i))/(S(i)+E(i)+I(i)+M(i)+R(i)));
E(i+1)=E(i)+h*((k_c*k_b*I(i)*S(i))/(S(i)+E(i)+I(i)+M(i)+R(i))-(k_a*E(i)));
I(i+1)=I(i)+h*((k_a*E(i))-(k_g*I(i)));
M(i+1)=M(i)+h*((k_g*I(i))-(k_w*M(i)));
R(i+1)=R(i)+h*((k_w*M(i)));
end
plot(T,S, 'b.-')
hold on
plot(T,E, 'k*-')
hold on
plot(T,I, 'r+-')
hold on
plot(T,M, 'c^-')
hold on
plot(T,R, 'gv-')
hold on
legend('Suceptibles','Exposed','Infected','Medicaly Semptomatic','Recovered')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend 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!
