LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MatLab Script Node - outputs are zero?!

I am running a MatLab script node with MatLab 2010a open on my computer, running with LabVIEW 8.5.

 

I have the script node with the correct inputs to it, and then some basic maths in the code, however when it comes to output, all the values are zero. 

When I had an input that it passes straight over to the output (of the same name) it works without a problem, but if I want to change the name of the output it outputs zero, along with if I attempt to do any maths using that input. 

 

I've attached the VI, if anyone gets a chance to take a look through and could tell me why MatLab can't seem to do maths anymore that'd be really helpful!

 

I have tried changing the format of the input and output (I think in the attached VI they are both set to DBL) and my apologies for the masses of outputs I've included - I wanted to see if any of the outputs were changing at all! 

 

Thanks in advance,

Dani

0 Kudos
Message 1 of 6
(2,482 Views)

P.S. the toggle button on the front panel needs to be set to False for the bit of code that I'm trying to sort at the moment. When it runs with True it just displays Not A Number - I haven't got round to fixing the True bit yet!

 

Additionally, I just realised I'd saved it mid-change so the input has been changed to a DBL whilst the output is now changing to EXT. I don't know why I saved it at that point! But I know that will be the first thing you may recommend I alter Smiley Wink

 

Dani

0 Kudos
Message 2 of 6
(2,479 Views)

Learn to use error clusters. If you create an error output on the script node you will see that you are getting a Matlab error: "Error: Unexpected MATLAB operator". Clearly, your script is incorrect. Like your other post, you seem to have problem with Matlab syntax, not LabVIEW. 

 

Of course, that doesn't mean you don't have LabVIEW issues. You do:

  • To have to resort to Matlab to perform that basic math is simply ludicrous. In your other post you said "To convert the mechanics of the labview programme into MatLab script (as this is what our students are taught) but using the LabVIEW front panels for their design and user interface". Sorry, but I don't see what this is teaching students.
  • Converting arrays to clusters just to get the elements. That's what Index Array is for. And, it's resizable to get more than one element. Do you convert arrays in Matlab to structures and then pull out individual elements, or do you index the arrays?
  • There is no loop in the code. Is this VI meant to run just once, or is it mean to stay running while you fiddle with the controls? If it's the latter, you need a loop. DO NOT USE THE RUN CONTINUOUSLY BUTTON. That's not what it's for. Using this is no different than clicking the Run button over and over.
0 Kudos
Message 3 of 6
(2,474 Views)

Thanks for that. 

It is a subVI from a much larger program - It will only run once when run in the entire process. 

The subVI was written by the previous person on this project - I am trying to update it, so thank you for the comments re. the clusters and arrays - I will ensure to edit that to index array for simplicity. 

Thank you for your comments on the codes too - I had read different articles etc, that had differences on whether the 'if' command was capitalised or not, so thanks for clearing that up for me! 

 

I will ensure to add error clusters from now on; that seems to be an invaluable tool!

Thanks,

Dani

0 Kudos
Message 4 of 6
(2,468 Views)

I am still getting an Error in my MatLab script, but it runs without a problem in MatLab itself. I receive the 'Unexpected MatLab operator' as you said before, but I'm not sure what this is as it doesn't pinpoint the line. With full realisation that this is a LabVIEW forum, but do you have an idea what the unexpected operator could be? Is there something I'm missing to start off my code? 

Thanks,

Dani

0 Kudos
Message 5 of 6
(2,459 Views)

Hello Dani,

 

I often support users with textual math, or imported textual code in LabVIEW.  When there are potential bugs in the imported text, the same rules as text based debugging apply.

 

One technique is to divide the lines by half. 

  1. Visually inspect the lines in the Matlab script node, and delete the second half of the lines. (after backing up).
  2. Does the code still error?  If Yes, then the error is in the first half of the code.  If No, than the error is in the second half. 
  3. Once you have isolated which half has an error, delete half those lines again.  Repeat the same process as above.  Eventually you will be left with 2 lines, and one of them, or both, will have the error.

What is the significance of the (**) operator?

Should '-dG' be replaced with (-1 *dG)?

That might be a starting point.

 

For the minute, I could also suggest that you may want to use a Formula Node box.  It supports textual math in LabVIEW using standard 'C' operators, and does not require MatLab to be installed on the PC.

 

By all means, however, I understand the importance of re-using something that has already been tried and tested in MatLab.

 

Regards,

 

George T.
Senior Applications Engineer
National Instruments UK and Ireland
0 Kudos
Message 6 of 6
(2,449 Views)