function can not retrive varaible value from other function

1 visualización (últimos 30 días)
Raza
Raza el 24 de Jul. de 2014
Respondida: Peter Babu el 24 de Jul. de 2014
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 comentario
Raza
Raza el 24 de Jul. de 2014
Editada: Raza el 24 de Jul. de 2014
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

Iniciar sesión para comentar.

Respuestas (2)

Julia
Julia el 24 de Jul. de 2014
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 el 24 de Jul. de 2014
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

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by