how does global function work in this code?

조회 수: 1 (최근 30일)
Fred
Fred 2013년 4월 5일
Hi, I am kind of beginner in MATLAB and I try to use the following code. It seems I should define p and q but I can not figure out how should I enter p and q to the code
function [CL,e,psi,r] = ARMA_FULL(theta0, data)
%function CL=ARMA_FULL(theta0,data)
% define the global vector
global p q;
x=data;
% initial parameter set theta0 is a column vector;
% c is the constant of the general ARMA model;
% ar is the (1*p) vector;
% ma is the (1*q) vector;
if p==0;
% initial parameters for pure moving average model
y=x-mean(x);
ma=theta0(2:end-1);
s=theta0(end);
.
.
.
  댓글 수: 1
per isakson
per isakson 2013년 4월 5일
Try to avoid globals. Don't make it a habit to use them.

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

채택된 답변

per isakson
per isakson 2013년 4월 5일
편집: per isakson 2013년 4월 5일
Try
>> global my_global
>> my_global= 17
my_global =
17
>> global_demo
17
>>
where
function global_demo()
global my_global
disp( my_global )
end
Matt Fig says: Globals not good.
Search for "globals evil"! You'll find: Global Variables Are Bad and more

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by