All pastes #342288 Raw Edit

Something

public text v1 · immutable
·published 2007-02-06 05:40 UTC
rendered paste body
%filename:gauss.m
function ret = gauss(sigma)

length = ceil(6*sigma); %create a vector 6 times sigma

if mod(length,2) == 0 
    length = length+1;
end %round to odd

redLength= (length-1)/2; %helps to calculate a vector of values for x
vec = rand(1,length); %initialize a vector of size length
for i=(-(redLength)):1:redLength
    vec(i+(redLength+1))=exp(-i^2/2*sigma^2);
end %iterate through array and calculate gauss for each value

vec=vec/sum(vec(:)); %normalize 
ret = vec;