LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

matlab script function in labview

Highlighted

Hello for everyone.

 

I am student and I am trying to do my project in LABVIEW by using MATLAB.

 

I want to make control system with MATLAB which will include 2 measured voltages in NI ELVIS 2 kit.

 

I succeed to generate this two voltages, but I can"t make them controled in MATLAB script, it always show "ERROR 1050"

 

and don"t recognize this function.

 

Please help me to understand where is my problem.

 

With best regards.

 

Dinerman Zori.

 

 

0 Kudos
Message 1 of 14
(2,409 Views)
Highlighted

Hi Dinerman,

The code that you have inside the MATLAB Script Node is not even exectuable inside the command window of MATLAB®, but it is executable when coded into an m-file. You probably want to take a close look at the difference between scripts and functions. If you remove you first line of your code from the MATLAB Script Node you will find that your VI will operate much better.

I also recommend the following links...

How can I Learn LabVIEW (look at the self pace training)
Getting Started with DAQmx (look at the Basic Programming with DAQmx)

MATLAB® is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.

Message 2 of 14
(2,349 Views)
Highlighted
your parameter vc must be declared as an input at the MATLAB node. Technically, there is nothing wrong with your code, only LabVIEW will want to pass the variable 'vc', hence, the variable 'vc' in your function parameter must be added as an input at the MATLAB node.
0 Kudos
Message 3 of 14
(2,344 Views)
Highlighted
One more thing. How many sample are you getting from your DAQ Assistant? The input to vc is accepting a double and it looks like your DAQ Assistant is outputing dynamic data (likely multiple samples). You may want to correct that...
0 Kudos
Message 4 of 14
(2,340 Views)
Highlighted
Hello Joshua B.
First of all, I wanna thank you for replying my email.
I saw the sites of DAQ and I learned some new stuff but i want finaly to measure my Input voltage value and Output voltage value in "looping real time" and to make result comparisment  .
how can I do it?
I didn"t understand how to use matlab script for looping in real time because if I make  loop in matlab script I get the resault in the end of the procedure.
can you give me some ideas or sites to learn from them?
P.S : I still don't understand where is my problem in Matlab Script Function (you can see in the picture).
with best regards .
0 Kudos
Message 5 of 14
(2,299 Views)
Highlighted

Dinerman,

 

You are welcome. I don't believe I understand what you are needing. Are you wanting to measure a voltage, use the MATLAB Script node to perform some analysis and then output some value to an analog output? What hardware are you using and what is your application?

 

It is probably not a good idea to loop inside the MATLAB Script Node unless you need your script to iterate for some reason . Can you not use a while loop around your whole program and execute in a repeated fashion so the program flow is read voltage in, analyze, and output new voltage? Of course, this statement depends on your application...

 

MATLAB® is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.

0 Kudos
Message 6 of 14
(2,266 Views)
Highlighted

Joshua B. hello.

 

YES, I want to measure a voltage, use the MATLAB Script node to perform some analysis and then output some value to an analog output.

I want build a circuit of BUCK  DC-DC converter :

 

 

 

 

 and build this circuit on this kit( NI ELVIS II).

I will measure the output and input voltage by DAQ which shown on this sites:

Building an Analog Input VI in NI-DAQmx-  http://zone.ni.com/devzone/cda/tut/p/id/5370 

Building an Analog Output VI in NI-DAQmx-  http://zone.ni.com/devzone/cda/tut/p/id/5371

when I will get the values of voltages,how can I make the comparation of them ,may I put them on matlab script and use like function?

the function which I want to use need compare these two values ,and

if

Vout<Voltage that I want,TURN ON VIN

if

Vout>Voltage that I want,TURN OFF VIN

 

I want to do this operation for routin mode (loop).

with regards.

 

0 Kudos
Message 7 of 14
(2,251 Views)
Highlighted

Hi Dinerman,

 

Ah yes, you said the Elvis II in your first post, didn't you Smiley Wink. Instead of using the MATLAB Script Node, why not use a Case Structure with Comparison Functions (more here) and Boolean Functions, or the Compairson Express VI to compare the voltage signals? 

 

MATLAB® is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.

 

0 Kudos
Message 8 of 14
(2,213 Views)
Highlighted

Joshua B hello.

 

I build this scheme on labview.

In this scheme I integrated output DAQ and input DAQ,the result is going to MATLAB script. and it is WORKINGSmiley Very Happy

for making the procedure to extended time,I put the while loop function, is it corectly?

I saw on osiloscope that I have the delay time between input and output result,how can I improve my delay time?

p.s: when I am making high friquency in the input, the system recognize and change the output once in a long while,how can I improve it?

 

 

with best regards.

0 Kudos
Message 9 of 14
(2,175 Views)
Highlighted

Hi Dinerman,

 

You made good progess.

 

  •  Yes, using the while loop will allow your VI to run continously
  • However, since you are new to LabVIEW why did you move to using the DAQmx functions instead of staying with the DAQmx Express Functions? I would recommend staying with the Express Functions until you are more comfortable with LabVIEW.
  • If you want to stay with the DAQmx functions you currently have, then you should move the DAQmx Create Channels, DAQmx Timing and Start task to the left outside of the while loop. Then move the Clear Tasks outside to the right of the while loop. Take a look at the Example Finder for examples on using the DAQmx Functions.Using the DAQmx Express Functions take care of seting up and clear task for you....
  • What is the purpose of the Function Generator VI with a 0 square wave frequency?
  • From what is in your Script Node and what you have mentioned in your previous posts I believe you are wanting to change your DAQmx Write task to 1Chan 1Samp so that you get the number from the Vout terminal of the script node and input it into your DAQmx Write task. You will need to change the DAQmx Timing node to Sample Clock. Since I believe you are just trying to output a constant value I just keep the rate at 1000.
0 Kudos
Message 10 of 14
(2,142 Views)