LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

matlab script

hey!!
with matlab script nodes, is there any way i can get labview to open matlab; run a matlab program; then output it in labview. what im saying is i don't want to add an input to the matlab script node in labview; i want labview to run my matlab program which already asks the user for an input. is this possible??
0 Kudos
Message 1 of 8
(4,509 Views)
The Matlab script node will run whatever script you enter, or you can have it call a script that you've already written. Thus, if you manually launch Matlab and run the script from there, you can do the same thing with the Matlab script node.
0 Kudos
Message 2 of 8
(4,506 Views)

but for some reason, labview won't open my matlab progam...

for example if my matlab script says this

x=input('what is x?')

y=input('what is y?')

z=x+y

and i want to display what z is; so i right click on the script node and add an output which is z and create an indicator. when i run the program, it doesn't work.

i would have to delete the first 2 lines of my matlab code; and right click on the script node and add input; twice one for x and one for y.

would you know how to make it so that i could just have it run the code without inputting in labview??

0 Kudos
Message 3 of 8
(4,501 Views)
If you entered those lines in the Matlab script node you need to declare x and y. You can do this by simply entering these lines:
x=0
y=0

To enter the values you need to type them into the Matlab Command Window that is displayed when LabVIEW connects to the Matlab script server. Note that this is NOT the same as the "regular" command window that is opened when you run Matlab from Start->Programs->etc. The command window that is opened when LabVIEW connects to the Matlab script server is smaller:



When the script asks for input you do not get the prompt, but you can type the values at the ">>" prompt. Below is an example of what this looks like:



This means that you should change the way you ask for input by, say, using dialog boxes.


Message Edited by smercurio_fc on 06-23-2008 10:43 AM
Download All
0 Kudos
Message 4 of 8
(4,479 Views)
If you have a newer versions of LabVIEW, you can substutute the mathscript node. It is pure LabVIEW and accepts matlab syntax.
 
Here's the prompt you would get using your code:
 
 
Everything works just fine. 😄
 
For further help for mathscript, see the Mathscript forum: http://forums.ni.com/ni/board?board.id=MathScript


Message Edited by altenbach on 06-23-2008 09:10 AM
0 Kudos
Message 5 of 8
(4,472 Views)
Good point, altenbach, although it should be appended with a caveat that Mathscript is not a complete replacement for Matlab. Clearly, for something as simple as this there's no problem. However, we have no idea what you're doing in Matlab, so there's no way to say that your existing Matlab script will work in Mathscript. Assuming, of course, that what you were presenting was just a simple example, and not what you're actually trying to do. If it is, you're better off coding it in LabVIEW in the first place. Smiley Wink
0 Kudos
Message 6 of 8
(4,457 Views)

hey smercurio,

i see what you are saying with the decalring the variables but that screen doesn't even pop up when i run my code.  i get an error 1048, it says Labview failed to get variable from the script server. do you know how to fix this?

0 Kudos
Message 7 of 8
(4,445 Views)
There are a number of reasons why you can get error code 1048: Why Does My Script Written in The MathWorks, Inc. MATLAB® Language Syntax Return Error 1048?

Do the Matlab examples that ship with LabVIEW work? Here's what I did, and as you can see it work, though it's not pretty:



That said, you should reconsider using Mathscript.

Also, what are you fundamentally trying to accomplish? Is this part of something bigger?


Message Edited by smercurio_fc on 06-23-2008 12:34 PM
0 Kudos
Message 8 of 8
(4,436 Views)