help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with an if statement inside a while loop


From: SikoraP13
Subject: Problem with an if statement inside a while loop
Date: Thu, 1 Aug 2013 06:51:05 -0700 (PDT)

Hi everybody.  I'm having a problem where Octave is giving me a parse error
syntax error problem with my code.  I've copied the code below.  The error
I'm receiving says 

parse error near line __ of file....

syntax error

>>> else
           ^


Can anyone provide any guidance as to what the problem might be? The problem
area in the code is denoted.  I want it to go through each point in
commandList, and change the X and Y positions and the angle accordingly and
add all of those points to the vector.




clear()
init='LFL+F+LFL'; %First Iteration (AXIOM)

L='-RF+LFL+FR-';  %INPUT GENERATORS HERE
R='+LF-RFR-FL+';

it= 4;                          %desired # of iterations
angle(1)= 0;            %Initial Angle
scalingFactor=4;        %Scaling Factor
angleInc=90;            %Angle Increment

pos=[0,0,0]                     %Initial X, Y, and Angle


i=1;
currentString(i)=cellstr(init);

for i=1:it-1
        newStringL= strrep(currentString(i),'L', 'C');
        newStringR= strrep(newStringL, 'R', R);
        newString= strrep(newStringR,'C', L);
        currentString(i+1)=newString;

endfor

commandList=currentString(1,it);
commandList=char(commandList);

ii=2;

%%%%%%%%%%%%%%%
%%%%PROBLEM%%%%
%%%%%%%%%%%%%%%

while ii<=length(commandList)+1
        if commandList(1,ii-1)=="+"
                (
                        %angle(i+1)=angle(i)+angleInc
                        pos(ii,:)=pos(ii-1,:)+[0,0,90]          
                )
        elseif commandList(1,ii-1)=="-"
                (
                        pos(ii,:)=pos(ii-1,:)-[0,0,90]
                        %angle(i+1)=angle(i)-angleInc           
                        
                )
        elseif commandList(1,ii-1)=="F"
                (
                
pos(ii,:)=pos(ii-1,:)+1./scalingFactor.^n.*[cos([pos(ii-1,3),sin([pos(ii-1,3),0]
                        %angle(i+1)=angle(i)            
                )
                
        else
                (
                        pos(ii,:)=pos(ii-1,:)
                        pos(ii-1,:)+1
                )
        endif
ii++
end             




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Problem-with-an-if-statement-inside-a-while-loop-tp4656310.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]