필터 지우기
필터 지우기

global variable inside a function

조회 수: 2 (최근 30일)
Babak
Babak 2014년 8월 25일
편집: per isakson 2014년 8월 26일
Hello every one, In my program I used a solver (ODE45) and as you know, for this purpose I need to define a function. I have an element in my function that change with respect to time. For having time in my function I defined global time but unfortunately I got array of my time. I need to have exact time that solver is using!!. What should I do?
t=0:0.001:2;
[tout,y]=ode45(@(t,X) sys1(X,B,L,Rr),t,zeros(50,1));
%%my function %%
function xdot=sys1(X,B,L,Rr)
global t;
Va=208*cos(2*pi*60*t);
end
Thanks in advance.

답변 (1개)

AJ von Alt
AJ von Alt 2014년 8월 25일
There is no need to use a global. You can pass t in as an argument to your ode function. Example 3 of the ode45 documentation demonstrates this usage.
  댓글 수: 1
Babak
Babak 2014년 8월 26일
Thank you AJ von Alt. :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by