01-18-2013 05:24 PM
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?!
Solved! Go to Solution.
01-18-2013 06:38 PM
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
01-18-2013 06:44 PM
Thank you so much!!