LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use global varible of Matlab in the mathscript node

Hello,

I have a main script that calls a function f1 and f1 includes another function f2.

f2 uses 4 global variables a, b, c and h.

When I run my script in Matlab, it works well: when I change the values of the 4 variables in the main script the code updates the values in f2 and runs.

I tried to copy the main script in the the mathscript node and I put the 4 variables as inputs of the node. But each time I change the values of the inputs, the script failed to update for the new values and kept giving the same results with the first values as the global variables are "frozen".

Is there a way to force the script to update the global variables in f2?

Thanks,

Zied

0 Kudos
Message 1 of 8
(3,799 Views)

Zied,

     By now, you should know that asking a question without posting code (in the form of an attach VI) is not helpful to us.  Please, please, please, post your code!!!

 

Bob Schor

0 Kudos
Message 2 of 8
(3,770 Views)

Sorry for the missing VIs.

I attached them here.

0 Kudos
Message 3 of 8
(3,727 Views)

ziedhosni,

 

I am looking through some of your MATLAB script in the file you uploaded and am not quite following what you are trying to do in the code. I only see the one function "lyapunov1" in your code and am searching for the second function. Would this be "Eq4_jieren_lyap" that I see?

 

Additional clarification - are you seening this variable "freezing" across multiple runs of the program, or are you expecting to see the variables update in "real time" as the program runs?

 

Thanks and have a great day,

 

Sam R.

Applications Engineer

National Instruments

www.ni.com/support

Sam R.
Message 4 of 8
(3,700 Views)

Hi Sam,

Thanks for looking through my code.

You are right, the second function is as what you said "Eq4_jieren_lyap".

I have a,b,c,h as inputs for the node and "Res" as output.

I expect that the change of the input will affect the output but this did not happen, which means thatLabiview could not update the variable. The run on Matlab only  allowed to  update the variables but when it is interfaced with Labview, it doesn't update.

Cheers,

Zied

 

0 Kudos
Message 5 of 8
(3,688 Views)

Hi Zied,

 

The part that I am unclear about is whether or not this runs correctly once and then fails to update in subsequent runs, or if it just does not run at all? If it is the case that it runs one time as expected, my first troubleshooting step would be to make 4 outputs from the node that calls variables a, b, c, and h to check whether or not these variables are actually being updated. 

 

I am interested in why the global variables are defined once in the main code and then again in "Eq4_jieren_lyap.m". Depending on how the MathScript Node handles this, it may be an unnecessary redefinition of your global variables. 

 

Best,

 

Sam R.
0 Kudos
Message 6 of 8
(3,659 Views)

Hi samurei.  From labview.  The value of a b c and h change in the output of the node as expected but apparently they don't get updated in the nested function. 

To be honest,  I thought it is mandatory to call the global variables in all the functions. 

The labview code generate the data once but once I change the values for a b c and h I get the same results as before. 

Cheers, 

Zied

0 Kudos
Message 7 of 8
(3,652 Views)

Zied,

 

This sounds like an issue with the bahavior of the 'global' scope of these variables. Typically we see global variables being defined in order to pass values between mathscript nodes in LabVIEW. The fact that we are dealing with nested functions and the redefinition of global variables is likely at the root of the problem. In the meantime between playing with your variable declarations, it may be worthwhile to consider refactoring your script such that it takes a, b, c, and h as direct inputs rather than calling on a global variable. 

Sam R.
0 Kudos
Message 8 of 8
(3,627 Views)