How can I get my fucntion to accept doubles.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matthew Robinson
le 4 Déc 2017
Modifié(e) : Stephen23
le 4 Déc 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 commentaires
Réponse acceptée
Stephen23
le 4 Déc 2017
Modifié(e) : Stephen23
le 4 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!