scope of a variable

조회 수: 3 (최근 30일)
biswajita lenka
biswajita lenka 2012년 1월 2일
hi, i am modifying a global variable inside a function.inside the function it works and stores the modified value.but when i am trying to access the same variable outside the function after it is modified,it is showing me the old value instead of the modified new value. can anybody help me?

채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 2일
Have you declared the variable as being global inside the function? Global variables are only global in routines that use the 'global' declaration (or in nested routines that share variables with a routine that declares them as global.)
Also, note that if you have declared a variable as a parameter to a function, and then in the function you declare it to be global, then it will not be treated as global: using a variable as a parameter overrides a global declaration.
  댓글 수: 1
biswajita lenka
biswajita lenka 2012년 1월 3일
thanks,it is working.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by