How do I stop MATLAB from giving me this warning? ( Global variables are inefficient and make errors difficult to diagnose. Use a function with input variables instead.)
    5 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Alvin Ang
 le 22 Déc 2021
  
    
    
    
    
    Réponse apportée : Image Analyst
      
      
 le 22 Déc 2021
            This is the code i used, how do i remove the warning underline below global?
clc;clearvars;close all;
 global x
 x=5;
 A = hello
  function A=hello()
      global x
      A= 5*x;
  end
0 commentaires
Réponse acceptée
  Star Strider
      
      
 le 22 Déc 2021
        The obvious solution is DO NOT USE GLOBAL VARIABLES! 
Here, thie solution is — 
 x=5;
 A = hello(x)
  function A=hello(x)
      A= 5*x;
  end
Define the function to have an argument and then pass the argument to it.  
.
0 commentaires
Plus de réponses (1)
  Image Analyst
      
      
 le 22 Déc 2021
        I haven't tried that one but I'm attaching my function for turning off other warnings.  
There are instructions in there for how to figure out how to turn off a particular warning such as the global one you're referring to.  Follow those instructions and adapt the function then call it in your opening routine.
0 commentaires
Voir également
Catégories
				En savoir plus sur Performance and Memory 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!