How do I wrap a Gaussian distribution around a polar plot?

I'm trying to wrap a Gaussian curve (code generated by the curve fitting app) to a polar plot, but my values at 0 degrees and 360 degrees aren't the same (but they should be). I've tried using the wrapToPi, but that doesn't seem to make the values any closer to each other (see fig below). Any ideas what may be going wrong?
if true
%%Load the data
y = [0.730 0.930 0.730 0.530 0.670 0.470 0.730 0.600]; % the first value would be repeated at 360 deg.
directions = deg2rad([0 45 90 135 180 225 270 315]);
cells = y;
numCells = 1;
ft = fittype( 'gauss1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
pp = polarplot(0,0); hold on;
%%Generate a fit for each cell
for cellNum = 1:1
% Get the current cell's data
currCellResponse = cells(cellNum, :);
% Interpolate the firing rate over a large number of directions
dirInt = 0:0.01:360;
dirInt = deg2rad(dirInt);
dirInt = wrapToPi(dirInt);
% Do the fit
[curve, gof] = fit(directions', currCellResponse', ft, opts);
a1 = curve.a1; b1 = curve.b1; c1 = curve.c1;
% Fit equation
yF = a1*exp(-((dirInt-b1)/c1).^2);
yF_mean(cellNum, :) = a1*exp(-((dirInt-b1)/c1).^2);
polarplot(dirInt, yF, 'k-');
end
drawnow;

Answers (0)

Asked:

on 25 Oct 2017

Edited:

on 25 Oct 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!