Path: news.mathworks.com!not-for-mail
From: "Jeff Hajewski" <jhajewsk@indiana.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Issue with horzcat
Date: Wed, 15 Apr 2009 00:11:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 177
Message-ID: <gs38mm$4pv$1@fred.mathworks.com>
References: <gs10ep$1vr$1@fred.mathworks.com> <gs1191$q0a$1@fred.mathworks.com> <gs2ah1$ff4$1@fred.mathworks.com> <gs2g1c$k4g$1@fred.mathworks.com> <gs2icq$b0m$1@fred.mathworks.com> <gs2jaa$gv1$1@fred.mathworks.com> <gs2kdv$k1j$1@fred.mathworks.com> <gs2l0m$khd$1@fred.mathworks.com> <gs30g5$dr8$1@fred.mathworks.com> <gs32nd$f1j$1@fred.mathworks.com>
Reply-To: "Jeff Hajewski" <jhajewsk@indiana.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1239754262 4927 172.30.248.38 (15 Apr 2009 00:11:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Apr 2009 00:11:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 942762
Xref: news.mathworks.com comp.soft-sys.matlab:532781


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(j-1) = -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(j-1) = -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