Matlab:无法绘制连续函数

时间:2014-02-15 22:37:52

标签: matlab plot

我想绘制浓度与时间之间的关系。

浓度和时间之间的关系表示为分段函数

  C(t) =0 for                           t>=0  & t <=td
  C(t) =A_max(t-td)                     t>=td && t<=t_max
         3   
  C(t) = Σ   a(n)*e^-(b(n)*(t-t_max))   t> t_max  /exponential decay 
         n=1  

值td和t_max是输入值

对于这个分段函数,我编写了以下函数,它接受td,t_max和系数如a1,a2,a3,b1,b2,b2的值,并绘制浓度Vs时间

function c_o = Sample_function(td,t_max,a1,a2,a3,b1,b2,b3)
t =(1:5:5000); % time of the sample post injection in mins
c_o =(0 : 2275.3 :113765); % activity of the sample calibrated with Average well counter    
A_max= max(c_o);%Max value of Concentration (Peak of the curve)

for i=1:length(t)

 if((t(i)>0) && (t(i)<=td))
    c_o(i)=0;

 elseif((t(i)>=td) && (t(i)<=t_max))
    c_o(i)= A_max*(t(i)-td);

 else(t(i)>t_max)
    c_o(i)=(a1*exp(-b1*(t(i)-t_max)))+(a2*exp(-b2*(t(i)- t_max)))+(a3*exp(-b3*(t(i)-t_max)));




 end


end


fprintf('plotting Data ...\n');
 %figure ;
 plot(c_o(i));
xlabel('time of the sample in minutes ');
ylabel('Activity of the sample Ba/ml');
title (' Input function: Activity sample VS time ');
pause;
end

上述函数必须绘制t,td.t_max,a1,a2,a3,b1,b2,b3的每个值的浓度值,并且曲线必须根据t,td.t_max的值相应地变化,a1,a2,a3,b1,b2,b3。

请检查我的代码,如果这是绘制明智功能的适当方式

1 个答案:

答案 0 :(得分:2)

我现在手头没有Matlab,所以我的回答可能不起作用 试试这个:
删除该行:

plot(c_o(t(i)),'erasemode','background');

并在end的{​​{1}}之后添加以下行:

积(c_o);

还有一件事似乎已经消失了。您定义t = [1 501 1001 1501 ... 4501]
然后在内部为您将c_o值更改为c_o(t(i))。这意味着您只需修改c_o的第1个,第501个,第1001个......值。这是为了吗?