0
votes

As Octave does not seem to bring a Gauss function for 1D or 2D by default I tried to define those functions by myself.

I started of with the definition

function [result] = Gauss(x,[x0 sigma])
result = 1/(sqrt(2*pi*sigma^2))*exp(-1(x-x0)^2/2*sigma^2)
end

which resulted in a subscript error

error: subscript indices must be either positive integers or logicals

I Tried to modify the function definition as follows:

function [result] = Gauss(x,[x0 sigma])

as I found a function gaussmf from Matlab, where you can pass an array x and single numbers in x0 and sigma. Unfortunately I still get a subscription error with that.

So my question is: How can I pass an array and additional non-array arguments in this case? I thought this would be rather automatic, but does not seem to be... ;)

Thanks

1
GNU Octave has normpdf() for the 1D case. You can't define functions that way. Please read the manual. - juliohm

1 Answers

0
votes

I suspect the error comes from:

exp(-1(x-x0)^2/2*sigma^2)

and I suspect you want

exp(-(x-x0)^2/2*sigma^2)

instead. As you have written it you are trying to index 1 with x-x0. In fact, if x is a vector, you probably want:

exp(-(x-x0).^2/2*sigma^2)