NI Home > Community > NI Discussion Forums

LabVIEW MathScript RT Module

Showing results for 
Search instead for 
Do you mean 
Reply
Active Participant X.
Active Participant
X.
Posts: 1,856
0 Kudos
Accepted Solution

unexpected token: {

Trying to check how LV 2011/Mathscript supports clusters, I tried a Matlab script written by a colleague (function definition) and could not get it to pass the parsing stage in the Mathscript node.

After correcting a few things that are not supported yet (such as the use a "~" for a dummy variable name, or anonymous function declaration), I ended up with a bizarre message:

 

 unexpected token: {

The details show:

Line 346, Column 4: unexpected token: {

 

Line 346, column 4 is the end of the script, following a "end" declaration, which ends a sub-function declaration. There is no "{" character there.

What gives?

Member
Patricia B
Posts: 149

Re: unexpected token: {

Hello,

 

Would you mind posting a screenshot of the MathScript node and the error message?

 

Thanks,

Patricia B.

National Instruments
Applications Engineer
Active Participant X.
Active Participant
X.
Posts: 1,856
0 Kudos

Re: unexpected token: {

Sure, here is the VI. I cannot define an output variable (it is a cluster), as LV won't let me define its type (since it does not understand the script).

 

Test Matlab Script.vi

 

The errors, as reported by the Error List window are:

 

Error_001.jpg

 

and:

 

Error_002.jpg

 

I am attaching the script, if this can help (BTW, it appears impossible to attach a file with a ".m" extension...)

Thanks!

Member
K_Scott
Posts: 39

Re: unexpected token: {

[ Edited ]

Hi X.

 

The { token error refers to the syntax you are using to define cell arrays. Currently, cell arrays are not supported in MathScript. You should be able to rewrite the mscript using structs instead of cell arrays.

 

Cheers!

 

K Scott

 

Active Participant X.
Active Participant
X.
Posts: 1,856
0 Kudos

Re: unexpected token: {

All right then. Thanks for taking a look at the script. I guess that makes an easy feature suggestion for MathScript/LV 2012...

Active Participant X.
Active Participant
X.
Posts: 1,856
0 Kudos

Re: unexpected token: {

Just checking if you guys are still willing to help. The author of the script removed cells and function handles from his script, but still MathScript does not seem to understand what's going on:

 

ScreenHunter_002.jpg

 

ScreenHunter_001.jpg

 

 

The modified script, with no cells, is attached.

Thanks in advance for your support.

Member
K_Scott
Posts: 39

Re: unexpected token: {

Hi X.,

 

There are a couple more issues in your script:

 

1. When using multiple functions within a single m-file we currently don't support the use of "end" at the end of a function description. For example, this would be ok:

  

function a = foo(x) 

 a=x;

function b = bar(y) 

 if y>3 

  b=y;  

 

wheras this would error:

 

function a = foo(x) 

 a=x;

end

function b = bar(y) 

 if y>3 

  b=y; 

 end

end

2. If possible you may wish to refrain from using global variables since it causes the MathScript Node to run in decreased performance mode. For more info look here.

 

3. You are still using varargin (which is not supported) in the Likelihood_subfunction parameters. You should treat this like you treated the original function call by replacing it with the total number of inputs you wish to use. In this case the four inputs required for the subfunction call.

 

4. You are using optimset to pass options to fminsearch. Currently optimset is not supported. Our default values for max iterations and max function calls are 100 and 1000 respectively. If you really need to set these values to something different we may have some ideas. Please send me a pm if that is the case. 

 

5. Finally, the syntax you use for fminsearch is not correct in MathScript. Our current implementation of fminsearch only supports two outputs. Having a third output (errflag) will cause this function to give an error.

 

This script has been very useful to use in providing a usecase for support that we currently lack. Thanks for sharing and let us know if we can be of more help.

 

Thanks,

 

K Scott

Active Participant X.
Active Participant
X.
Posts: 1,856
0 Kudos

Re: unexpected token: {

Thanks for the detailed answer, that is very helpful.

Not as much can be said of the LabVIEW error message!

Active Participant X.
Active Participant
X.
Posts: 1,856
0 Kudos

Re: unexpected token: {

I am attaching the modified version that now works (with the project, VI and a test file). However "works" is an overstatement... The first time the VI is run, processing takes ~100 s on my 3.4 GHz computer. The second and following times are down to ~20 s but that's anyway light years away from the ~50 ms reported by my colleague using Matlab...

I have tried to remove any reference to global variables (which returns the wrong numerical results but does not break the code) and the speed is barely improved (it gets a bit faster, ~ 8s after the first run, maybe because the number of iterations is reduced).

So why is such a code so much slower than when run in Matlab (to the point of being useless)?

Another puzzling behavior is that the MathScript node seems to return no error and then still keeps LabVIEW busy for a few seconds (I see that because I have an OpenG tick counts VI connected to the Error output of the MathScript node, and the tick counts value is updated on the front panel before the VI ends (and eventually outputs the numerical values). Why would that be?

Member
K_Scott
Posts: 39

Re: unexpected token: {

Hi X.,

 

Sorry for the delayed response. After further investigation we have found that our current implemenatation of fminsearch runs very slowly. Couple that with the globals that still exist in the code and this script is going to run with reduced performance. We are aware of these issues and are working on solutions to them. I am afraid that I can offer no further advice other than rewriting that piece of the script in LabVIEW native code.

 

Thanks,

 

-K Scott