How to properly plot data points

1 vue (au cours des 30 derniers jours)
Dakota Burrow
Dakota Burrow le 7 Juil 2013
Hi, I need to know the proper way I should plot my data such that I do not have to plot within the for loop, and so that the points will connect with a line.
clc
clear
SO = 8;
vm = 0.7;
ks = 2.5;
F =@(sm,t) SO-vm*t+ks*log(SO/sm)-sm;
sl = 0;
su = 9;
n = 6;
es = 0.5*10^(2-n);
for t = linspace(0,40,50)
sm = michaelis_menten(sl,su,es,t,F);
hold on;
plot(t,sm,'-');
hold off;
end
xlabel('Time(day)');
ylabel('Subtrate Concentration (moles/L)');
title('Substrate Concentration vs Time');
the function michaelis_menten is
function sm = michaelis_menten(sl,su,es,t,F)
ea = 1;
so = 1*10^8;
while ea > es
sm = (sl+su)/2;
if F(sl,t)*F(sm,t)< 0
su =sm;
elseif F(sl,t)*F(sm,t)>0
sl = sm;
else
so = sm;
end
ea = 100*abs((sm - so)/sm);
so = sm;
end
end

Réponse acceptée

the cyclist
the cyclist le 7 Juil 2013
Here's one way:
numberTimes = 50;
t = linspace(0,40,numberTimes);
figure
for nt = 1:numberTimes
sm(nt) = michaelis_menten(sl,su,es,t(nt),F);
end
plot(t,sm,'-');
xlabel('Time(day)');
ylabel('Subtrate Concentration (moles/L)');
title('Substrate Concentration vs Time');
If your subfunction could be vectorized (which I did not check), you could avoid the for-loop completely.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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!

Translated by