필터 지우기
필터 지우기

global variable not working.

조회 수: 3 (최근 30일)
Sameer
Sameer 2014년 5월 19일
댓글: Geoff Hayes 2014년 5월 19일
function [f] = objfun(n)
global f;
f = var(n);
end
How is the global variable not working
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2014년 5월 19일
Hi Sameer,
Please clarify the statement how is the global variable not working. What do you mean exactly?
Note that you are returning a parameter named f and you have declared a global variable with the same name. Why? There is no need to declare your return parameter as global.
Geoff

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

답변 (1개)

Image Analyst
Image Analyst 2014년 5월 19일
You don't need to make f global if you're returning it to the caller. Why? Why do that? Declaring it global inside objfun means that f now takes on whatever value it had last instead of being a local variable. But then you just overwrite that value , so there was absolutely no point in making it global since you didn't even use its global value. Delete that global line of code.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by