How to use one function in another function
    11 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Sushanth Manchikatla
 le 28 Juil 2020
  
    
    
    
    
    Réponse apportée : Sriram Tadavarty
    
 le 28 Juil 2020
            If I have a function f1 defined in a f1.m file and another f2 in f2.m, how to use these two functions in another function definition f3 in f3.m? And How do I use variables created/ used  in the f1 and f2 files, in the f3 function?
0 commentaires
Réponse acceptée
  Sriram Tadavarty
    
 le 28 Juil 2020
        Hi Sushanth,
When the functions f1 and F2 are in the path where function f3 can acess, then you can directly use the functions name to access the function.
For example,
function out = f3(in1,in2) a = f1(in1); % call th function signature end As shown above the usage with f1, even F2 can be called within the function f3.
The scope variables within a function are only present till the execution is within the function. Thus, you cannot acces intermediate variables of f1 and f2 in f3. In case it is required to use them, pass them as outputs to the respective functions.
Hope this helps. Regards, Sriram
0 commentaires
Plus de réponses (1)
  KSSV
      
      
 le 28 Juil 2020
        Easy save all the functions in same folder and run. 
function val = TwoSum(a,b) 
val = a+b; 
end
function val = ThreeSum(a,b,c) 
val = a+b+c ;
end
function out = Check(a,b,c)
sum1 = TwoSum(a,b) ; 
sum2 = ThreeSum(a,b,c) ; 
out = sum1+sum2 ; 
end
0 commentaires
Voir également
Catégories
				En savoir plus sur Entering Commands dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


