Why does it not plot the function?

5 次查看(过去 30 天)
In the following series of functions, only the 1st one is being plotted. I don't understand why the others don't appear. Could you help?
function ode_metabolism
tau1= 2; %%1st time const of neural feedback
tau2= 4;
t=0:0.1:1000; % time scale
initial_xm = 0;
initial_dxmdt = 0;
[t,x]=ode45( @Fm, t, [initial_xm initial_dxmdt] );
%
% plot(t,x(:,1));
% xlabel('t'); ylabel('xm');
function dxmdt=Fm(t,x)
dxdt_1 = x(2);
dxdt_2 = (-tau2*x(2) - x(1)+eps*0.5)/tau1^2;
dxmdt=[dxdt_1; dxdt_2];
end
end
%%flow
function ode_q
q=12;
q_b=12.5;
G_q= 3; %%gain of flow based feedback mechanism
tau_q= 20; %%[s] time const of flow based feedback mechanism
t=0:0.1:100; % time scale
initial_xq = 0;
[t,xq]=ode45( @Fq, t, [initial_xq] );
plot(t,xq(:,1));
xlabel('t'); ylabel('xq');
function dxqdt=Fq(t,xq)
dxdt1 = (-xq +G_q* (q-q_b)/q_b)/tau_q;
dxqdt=[dxdt1];
end
end

采纳的回答

OCDER
OCDER 2017-10-13
编辑:OCDER 2017-10-13
Only the 1st function, ode_metabolism, is called since it is considered the main function.
Your ode_q function is viewed as a local function , which must be summoned by the main function, ode_metabolism, to be used.
To fix this, either have ode_metabolism call ode_q, OR make another main function that calls ode_metabolism and ode_q as local functions, like this:
function ode_main
ode_metabolism;
ode_q;
end
function ode_metabolism
...
end
function ode_q
...
end

更多回答(1 个)

Image Analyst
Image Analyst 2017-10-13
You commented out the plot() call in ode_metabolism(), and the function ode_q() never gets called so the plot() in there never gets called either.
  2 个评论
gorilla3
gorilla3 2017-10-13
yes, if I uncomment the metabolism() one it works. But the other plot never works and I don't know why cause it's the same code as above
Image Analyst
Image Analyst 2017-10-13
It's because the ode_q() function is never called by your code, so how could that plot ever get called?

请先登录,再进行评论。

类别

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