How to properly plot data points

2 次查看(过去 30 天)
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

采纳的回答

the cyclist
the cyclist 2013-7-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by