LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathscript - unexpected token: function

Hi,
 
i want to define my own function in Mathscript using the syntax function outp = functionname (inp1, inp2) as shown in the LabVIEW help.
But it always says: unexpected token: function. Why?
 
Pleas help me Smiley Indifferent
0 Kudos
Message 1 of 4
(4,288 Views)
Hello,

This error generally means you are trying to run the function from the MathScript Window's script editor instead of calling the function with parameters.  Try saving your function as functionname.m and then calling it from the MathScript window by typing
functionname(inp1, inp2)
in the command window.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 2 of 4
(4,277 Views)
I have the same problem.  When I define function
ave=compute_average(x,y)
%compute_average determine the average
ave=(x+y)/2;
save it and run in the mathscript windows
it shows "Unknown symbol on line 1: compute_average"
why is that?

Sunan
0 Kudos
Message 3 of 4
(4,229 Views)
Hello Sunan,

In order to define a function, you must use the function keyword.  Try changing the first line of your file to be
function ave = compute_average(x, y)

The error you are seeing is because your file is currently interpreted as a script.  The first line is interpreted as a function call to compute_average, which MathScript cannot find.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 4 of 4
(4,200 Views)