How can I get my fucntion to accept doubles.
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Matthew Robinson
 il 4 Dic 2017
  
    
    
    
    
    Modificato: Stephen23
      
      
 il 4 Dic 2017
            Hi there,
I'm looking to create a function, which operates from its own file, where I can give it a double value, it does some math, and then it provides an answer based on the equation and variables detailed in the function. For example, the function file that I have created contains code that is something like:
 function f = CalcGaussValue(x)
       a1 =       10.25;
       b1 =    0.005067; 
       c1 =    0.009325;
       a2 =       267.1;
       b2 =      0.0148;
       c2 =     0.03119;
       f(x) = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)
 end
It runs perfectly fine with integers, yet come back with an error when it is given a double (which is what I would prefer to give it). When using an iput value of 1.1 for example, the error states: "Attempted to access (1.1); index must be a positive integer or logical"
Any help here would be greatly appreciated.
0 Commenti
Risposta accettata
  Stephen23
      
      
 il 4 Dic 2017
        
      Modificato: Stephen23
      
      
 il 4 Dic 2017
  
      This makes no sense:
f(x) = ...
because you are trying to do is use x as an index, which clearly makes no sense for non-integer values. Probably what you meant was to simply allocate to a variable:
f = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Logical in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

