LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mathscript error

Solved!
Go to solution

Hello, I am using the book "Hands-On Introduction to LabVIEW for Scientists and Engineers" by John Essick, and in chapter 3 it tells you to type a code into mathscript.  However, I keep getting an error on the last line, saying: Line 17, Column 4: expecting "end", found ''

This is the code I entered, copied straight from the book:

 

delta_t=1/f_s
start=0
step=delta_t
stop=(N-1)*delta_t
t=start:step:stop

if s==0
     x=A*sin(2*pi*f*t)
else if s==1
     x=A*cos(2*pi*f*t)
else if s==2
     x=linramp(A,A,N)
else if s==3
     x=A*gensignal('square',1/f,stop,step)
else if s==4
     x=4.0*sin(2*pi*100*t)+6.0*cos(2*pi*200*t)
end

 

 

What am I doing wrong?!

 

0 Kudos
Message 1 of 3
(2,761 Views)
Solution
Accepted by topic author jhauck1

Hello, jhauck

You must finish every "if" statement with "end".

Proper code would be:

if s==0
     x=A*sin(2*pi*f*t)
else
     if s==1
          x=A*cos(2*pi*f*t)
     else
          if s==2
               x=linramp(A,A,N)
          else
              if s==3
                   x=A*gensignal('square',1/f,stop,step)
              else
                   if s==4
                        x=4.0*sin(2*pi*100*t)+6.0*cos(2*pi*200*t)
                   end
              end
          end
     end
end

 

OR you can use "elseif" statement:

if s==0
     x=A*sin(2*pi*f*t)
elseif s==1
     x=A*cos(2*pi*f*t)
elseif s==2
     x=linramp(A,A,N)
elseif s==3
     x=A*gensignal('square',1/f,stop,step)
elseif s==4
     x=4.0*sin(2*pi*100*t)+6.0*cos(2*pi*200*t)
end

 

Refer to Matlab documentation: http://www.mathworks.com/help/matlab/ref/if.html

0 Kudos
Message 2 of 3
(2,753 Views)

Thank you so much!!

0 Kudos
Message 3 of 3
(2,748 Views)