MATLAB: How to get the fucntion to accept doubles.

doublesfunctionsMATLAB

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.

Best Answer

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);