Matlab passing variables to a function- I want these variables updated

2 vues (au cours des 30 derniers jours)
kajalschopra
kajalschopra le 2 Août 2015
Commenté : kajalschopra le 2 Août 2015
I have several instances in my matlab code wherein I want to pass varaibles to a function -
say,
Function A calls Function B passing an argument x.
x is updated by Function B.
Now, I want to use this updated value of x in Function A.
But this does not seem possible.
One way is that I declared x as global in function B and function A.
But if I do not want to do that, what is the best way to handle such a scenario?
Kajal

Réponse acceptée

the cyclist
the cyclist le 2 Août 2015
Modifié(e) : the cyclist le 2 Août 2015
Pass it back out again:
[x] = function B(x)
x = 2*x;
Call it like this, from A:
x = B(x)
  1 commentaire
kajalschopra
kajalschopra le 2 Août 2015
Thanks a lot! Just been into FORTRAN coding since 2 years!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fortran with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by