LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW support for user defined mathscriprt function calls

Hi,

I`ve been trying to incorporate mathscript function calls in LabVIEW .

However am denied the functions and throws "unexpected token: function" error.

Even the basic examples with function calls refuse to work .

Would like to know if there are any work arounds for this or has NI removed the

support to function calls in mathscript.

I am currently using LabVIEW 8.6. 

 

This is the script I have been trying to execute :

 

function ave=compute_average(x,y)

%compute_average determine the average

ave=(x+y)/2; 

 

Regards,

Sundar. 

0 Kudos
Message 1 of 5
(2,846 Views)

Have you followed the steps mentioned here:

MathScript Function Syntax

 

Be sure to try the DevZone linked mentioned at the bottom of that page.

Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 2 of 5
(2,836 Views)

Yes , I have followed the standard mathScript Syntax.

Not sure if am missing out any critical settings..

 

The sample code stated above is very much adhered to the specified syntax.

 

 

Sundar. 

0 Kudos
Message 3 of 5
(2,812 Views)
Hello Sundar,

Your syntax is valid.  However, the error message you received indicates that you are trying to run the function directly in the MathScript Window or the MathScript node.  Functions cannot be run; they must be called.  To that end, you need to write the function in an external .m file in order to call it from MathScript.

The .m file must be placed in a location where MathScript can find it.  The default search path for .m files is your "My Documents\LabVIEW Data" folder.  If you put your function text in a file called compute_average.m in that location and from the MathScript window type
a = compute_average(4, 6)
you should see the expected result.  You can browse the MathScript examples for other uses of user-defined functions (UDF) in <LabVIEW Install dir>\examples\MathScript.  In particular, the Heat Equation and the Riemann Zeta examples use UDFs.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
Message 4 of 5
(2,802 Views)

GrantM is correct.

Pre-existing scripts must be called, you do not need to write the entire script in the node.

Just call it, and include the parameters as inputs.

 

 

If you would like to run code the way you listed above, you can use the formula node to calulate things in place.

formula.PNG

Message Edited by Cory K on 06-05-2009 12:46 PM
Cory K
0 Kudos
Message 5 of 5
(2,800 Views)