LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Indicator update erratic from Matlab scriptnode output

I have written a somewhat complex VI that executes a Matlab scriptnode in one panel of a flat sequence stucture.  The flat
sequence structure itself is within a precision timing loop.  The input to the scriptnode is an array of data from a spectrum analyzer
which is captured and displayed (using the waveform display VI) prior to the Matlab scriptnode, so I know the data that Matlab is receiving
is valid.  (I also know the data is valid because I collect it and save in a .mat file from within Matlab so I can look at it later.)

Now my problem:  I have three Matlab output variables that are tied into LabView indicators residing in the same panel of the
flat sequence.  However, those indicators do not seem to be updated reliably.  Sometimes the indicators are updated correctly,
but more often than not the indicators are updated only once every few times through the precision timing loop. 

Has anyone else seen this kind of problem?  I am using LabView 7.1.1 and Matlab R2006a.  Suggestions welcome...
0 Kudos
Message 1 of 7
(3,354 Views)
Hello,
 
It would be hard for us to tell what exactly might be happening. Could you please post your VI or maybe something that can be used to reproduce this behavior?
 
Regards,
Chetan K
Application Engineer
National Instruments
0 Kudos
Message 2 of 7
(3,346 Views)
Chetan,

Here's the VI.  If you have an HP-8565E and three signal sources (that you can combine) handy, you can recreate the operating environment.
Note that there are two Matlab scriptnodes -- one outside the precision timing loop and one inside the timing loop.  The one outside the loop
performs a table lookup to set a variable based on an input control.  The one inside the timing loop takes the array of 601 points, separates it
into three regions, and finds the frequency at which the peak occurs in each region.  And if you don't have that equipment, well, there's enough
there for you to cut-paste and recreate the problem some other way.  Thanks for looking...
0 Kudos
Message 3 of 7
(3,339 Views)

Hello,

 

I looked at your VI and have couple of questions/suggestions for you to try.

Is there a specific reason why you are using a timed loop instead of a regular while loop? It could be possible that the code inside the loop is taking longer to execute than the "dt" that you specified.

Please connect a boolean indicator to "Finished Late" output on the output-node of the timed loop to verify this. Also I don’t think you would need to have the extra delay of 1000ms in the 3rd frame of the flat sequence structure since you have already specified the "dt". I also believe that the "Stop Capture" button should be inside the timed loop so that a new value can be read for every iteration.

 

Please try using a regular while loop in your code to see if it makes a difference.

 

I don’t have the Matlab and the specific instrument available to me, so I am not in a position to explicitly test this code out.

 

Let us know how it goes.

 

Regards,

Chetan K

Application Engineering

National Instruments

Message Edited by CKap on 12-12-2006 06:30 PM

0 Kudos
Message 4 of 7
(3,326 Views)
Chetan,

I made a copy of the VI and swapped out the timed loop for a standard while loop.  It made no noticeable difference -- update of the indicators was still erratic, happening perhaps once every 5-10 iterations.  Back over in the timed loop version, I added in the "Finished Late" boolean indicator as you requested and found that it did indicate a late finish if I set the "sampling interval" control to 3 seconds or less.  At 4 seconds -- which I had been using -- it reliably completed the loop.

I also added Error indicators on the timed loop and the Matlab scriptnodes.  In the timed loop version, no errors were indicated on the timed loop.
On the while loop version, the Matlab error indicator did register a 1048 error on one occasion and said that the Scriptnode server failed to pick up a variable that Matlab had made available to it, so perhaps there is something going on there that might merit further investigation by folks at NI.  (I'll take a look, too, but remember, I am already at LV 7.1.1 with version R2006a of Matlab, and word has gotten out that this is supposed to work, even though it hasn't been tested enough to give it the "supported" label.)   I will close here by informing you that I also single-stepped thorough the while loop version of the code in "Highlight execution" mode, and in this case, all of the indicators were updated properly.  So again, this suggests some sort of "full execution speed" incompatibility between LV 7.1.1 and Matlab R2006a.

Further suggestions welcome, but any that are large time sinks may have to wait until I get some real work done.
0 Kudos
Message 5 of 7
(3,313 Views)
Hello,
 
I am pretty sure that Matlab 2006b is compatible with our latest release of LabVIEW (ver 8.20), but since Matlab 2006b was recently released (september 2006) I dont think we can guarantee its compatibility with LabVIEW 7.1. I will have to double check with R&D on this to find out what kind of testing (if any) they performed to to check the compatibility of older version of LabVIEW and Matlab 2006b.
 
About your error message, I found this KnowledgeBase. Please have a look at it. It might be possible that there is something particular to the script itself. Have you tried running simpler scripts in the Matlab Script Node? That might hold a key to this issue.
 
Regards,
Chetan K
Application Engineering
National Instruments
0 Kudos
Message 6 of 7
(3,301 Views)
Chetan,

I saw that KB article as well.  You can see from the VI I posted that I was not using any Matlab "reserved keywords" in my scriptnode.  Nor was I clearing all my variables, but
I was clearing select variables in order to permit re-entry to the scriptnode as part of the loop it is in. 

Over the weekend, I restructured and rewrote portions of the VI.  There are no longer any Matlab scriptnodes within the loop.  Static portions of that scriptnode were moved to the initialization scriptnode outside the loop, and the dynamic portions of the code within the loop are now completely graphical.  And the indicators work properly.  Still, I'm not a happy camper because Matlab is practically a second language.  The scriptnode that took me 10 minutes to write in Matlab took several hours to replace with graphical programming. 

To answer your previous question about why I was using the timed loop, the VI I posted was actually a stripped-down version of a more complicated data-logging VI.  In that more complicated VI, data were captured by the spectrum analyzer, displayed on a waveform in LabView, and then passed to Matlab and stored in a .mat file for later use by other Matlab code.  However, that VI did not have any outputs on the scriptmode.  I wished to record the data at precise intervals, hence the use of the timed loop.  I created the VI I posted in order to allow me to do some interactive (hence the use of scriptnode outputs and the indicators) observation and tuning of frequencies of my signal sources.  The 1 second time burn you saw in the VI was my attempt to act on a poor hunch -- that adding a frame to burn some time might alter the code execution to cause the indicators to display properly.

Today I discovered another anomalous behavior between LV 7.1.1 and Matlab R2006a:  String controls do not seem to be passed properly into Matlab unless they are saved
as the default values before a VI is run.  I specified a "save" file for Matlab in a control on the front panel, then ran the VI without a default save.  At the end of an hour, I closed
the VI and discovered, to my horror, that the .mat file was not saved.  After specfiying a save file, saving the defaults, and then running the VI, the saved data .mat file was properly
created.
0 Kudos
Message 7 of 7
(3,298 Views)