Problem with the legend command
1 view (last 30 days)
Show older comments
Hi, I have an issue with the legend command. When the legend command is coded, it should be showing the graph line respectively. But now my problem is the legend command it gives me the same line graph color. May I know how to solve it? I will be grateful that someone can solve this matter. Thanks!
Here is the source code:
%% Initialize Input
K = 1000000000; % Carrying Capacity of Brain Tumor
C0 = 40000; % Initial Brain Tumor Population Size
r = 4.31*(10^-3); % Growth Rate of Brain Tumor Cells
kt = 0.9; % Fractional tumor cells killed by drugs of chemotherapy
D = 0.001; % Chemo Doses
%% Model Data
t = 1:7300; % Time in Days
% Calculating Brain Tumor Population
C = (C0*K)./(C0+((K-C0)*exp(-r*t)));
C1 = (C0*K)./(C0+((K-C0)*exp(-(r-kt*D)*t)));
%% Graph Plotting
figure (1)
plot(t,K,'--co','LineWidth',0.5,'MarkerSize',5,'MarkerEdgeColor','cyan')
hold on
plot(t,C,'--bo','LineWidth',0.5,'MarkerSize',5,'MarkerEdgeColor','black')
hold on
plot(t,C1,'--ro','LineWidth',0.5,'MarkerSize',5,'MarkerEdgeColor','red')
hold on
title( 'Brain Tumor Population Against Time' )
xlabel('Time (Days)')
ylabel('Brain Tumor Population (cells)')
legend('k','Without Chemotherapy','With Chemotherapy')
grid
Here is the output:
0 Comments
Accepted Answer
KSSV
on 6 Jan 2022
%% Initialize Input
K = 1000000000; % Carrying Capacity of Brain Tumor
C0 = 40000; % Initial Brain Tumor Population Size
r = 4.31*(10^-3); % Growth Rate of Brain Tumor Cells
kt = 0.9; % Fractional tumor cells killed by drugs of chemotherapy
D = 0.001; % Chemo Doses
%% Model Data
t = 1:7300; % Time in Days
% Calculating Brain Tumor Population
C = (C0*K)./(C0+((K-C0)*exp(-r*t)));
C1 = (C0*K)./(C0+((K-C0)*exp(-(r-kt*D)*t)));
%% Graph Plotting
K = K*ones(size(t)) ;
figure (1)
plot(t,K,'c','LineWidth',0.5)
hold on
plot(t,C,'b','LineWidth',0.5)
plot(t,C1,'r','LineWidth',0.5)
title( 'Brain Tumor Population Against Time' )
xlabel('Time (Days)')
ylabel('Brain Tumor Population (cells)')
legend({'k','Without Chemotherapy','With Chemotherapy'})
grid
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!