function can not retrive varaible value from other function

조회 수: 3 (최근 30일)
Raza
Raza 2014년 7월 24일
답변: Peter Babu 2014년 7월 24일
i have have generated two functions. function 2 can not pick the variable value, generated in function one,
what is the solution to utilize the variable value generated in function 1?
  댓글 수: 1
Raza
Raza 2014년 7월 24일
편집: Raza 2014년 7월 24일
function 1
function x
y= 2+2
end
function 2
function h
j=h+2
end
when i run function 2 error is generated that undefined variable h

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

답변 (2개)

Julia
Julia 2014년 7월 24일
I do not understand your code.
What should work to let the second function use the first:
ans=function2(function1(input))

Peter Babu
Peter Babu 2014년 7월 24일
Make the variable to global. Check the below code.
function 1() global x; x = 10; x = x+10
return
function 2() global x; global y; y = 0; y = y+20; display(x); return
function test() global x; global y;
display(x);
display(y);
return

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by