Here is the code before taking away the transpose:
function buildCurve(X,Y)
mx = mean(X);
my = mean(Y);
Xtrans = X  mx;
Ytrans = Y  my;
[theta,rho]=cart2pol(Xtrans,Ytrans);
%theta = mod(theta, 2*pi);
%Sort polar coord's so angles are in ascending order.
Pmatrix = [theta rho] %2xN matrix of polar coord's.
Pmatrix2 = Pmatrix.'; %Transpose, giving Nx2 matrix,col1=thetas & col2=rhos.
ortPmat = sortrows(Pmatrix2); %Sorts coord's ascendingly by angle.
%Shift thetas by 2*pi & +2*pi, emphasize periodicity.
NegCopyPmat = ortPmat;
NegCopyPmat(:,1) = NegCopyPmat(:,1)  2*pi;
PosCopyPmat = ortPmat;
PosCopyPmat(:,1) = PosCopyPmat(:,1) + 2*pi;
%Concatenate transposes of these matrices.
periodPmat = [NegCopyPmat.' ortPmat.' PosCopyPmat.'];
periodPmat = periodPmat.'; %Transpose back.
for j =2:(length(theta)1)
thetag(j1) = theta(j);
end
theta;
thetag = thetag';
%define
for i=1:length(thetag)
newRho = spline(periodPmat(:,1),periodPmat(:,2),thetag(i));
newPoint = [thetag(i)'; newRho];
%Adds new point to initial Point matrix.
size(ortPmat)
size(newPoint)
ortPmat
newPoint
ortPmat = horzcat(ortPmat', newPoint);
ortPmat = sortrows(ortPmat.');
%Shifts new ortPmat for periodicity.
NegCopyPmat = ortPmat;
NegCopyPmat(:,1) = NegCopyPmat(:,1)  2*pi;
PosCopyPmat = ortPmat;
PosCopyPmat(:,1) = PosCopyPmat(:,1) + 2*pi;
%Concatenate transposes of these matrices.
periodPmat = [NegCopyPmat.' ortPmat.' PosCopyPmat.'];
periodPmat = periodPmat.'; %Transpose back.
end
[newX newY] = pol2cart(THETA,RHO);
newX = newX + mx;
newY = newY + my;
plot(newX,newY)

Matlab Output

??? Error using ==> horzcat
All matrices on a row in the bracketed expression must have the
same number of rows.
Error in ==> buildCurve at 45
ortPmat = horzcat(ortPmat', newPoint);
45 ortPmat = horzcat(ortPmat', newPoint);
K>> whos ortPmat newPoint
Name Size Bytes Class
newPoint 2x1 16 double array
ortPmat 2x51 816 double array
Grand total is 104 elements using 832 bytes

Here is the code after taking away the transpose:
function buildCurve(X,Y)
mx = mean(X);
my = mean(Y);
Xtrans = X  mx;
Ytrans = Y  my;
[theta,rho]=cart2pol(Xtrans,Ytrans);
%theta = mod(theta, 2*pi);
%Sort polar coord's so angles are in ascending order.
Pmatrix = [theta rho] %2xN matrix of polar coord's.
Pmatrix2 = Pmatrix.'; %Transpose, giving Nx2 matrix,col1=thetas & col2=rhos.
ortPmat = sortrows(Pmatrix2); %Sorts coord's ascendingly by angle.
%Shift thetas by 2*pi & +2*pi, emphasize periodicity.
NegCopyPmat = ortPmat;
NegCopyPmat(:,1) = NegCopyPmat(:,1)  2*pi;
PosCopyPmat = ortPmat;
PosCopyPmat(:,1) = PosCopyPmat(:,1) + 2*pi;
%Concatenate transposes of these matrices.
periodPmat = [NegCopyPmat.' ortPmat.' PosCopyPmat.'];
periodPmat = periodPmat.'; %Transpose back.
for j =2:(length(theta)1)
thetag(j1) = theta(j);
end
theta;
thetag = thetag';
%define
for i=1:length(thetag)
newRho = spline(periodPmat(:,1),periodPmat(:,2),thetag(i));
newPoint = [thetag(i)'; newRho];
%Adds new point to initial Point matrix.
size(ortPmat)
size(newPoint)
ortPmat
newPoint
ortPmat = horzcat(ortPmat, newPoint);
ortPmat = sortrows(ortPmat.');
%Shifts new ortPmat for periodicity.
NegCopyPmat = ortPmat;
NegCopyPmat(:,1) = NegCopyPmat(:,1)  2*pi;
PosCopyPmat = ortPmat;
PosCopyPmat(:,1) = PosCopyPmat(:,1) + 2*pi;
%Concatenate transposes of these matrices.
periodPmat = [NegCopyPmat.' ortPmat.' PosCopyPmat.'];
periodPmat = periodPmat.'; %Transpose back.
end
[newX newY] = pol2cart(THETA,RHO);
newX = newX + mx;
newY = newY + my;
plot(newX,newY)

Matlab Output

??? Error using ==> horzcat
All matrices on a row in the bracketed expression must have the
same number of rows.
Error in ==> buildCurve at 45
ortPmat = horzcat(ortPmat, newPoint);
45 ortPmat = horzcat(ortPmat, newPoint);
K>> whos ortPmat newPoint
Name Size Bytes Class
newPoint 2x1 16 double array
ortPmat 52x2 832 double array
Grand total is 106 elements using 848 bytes
