Using Matlab script in Labview
Hello,
I am trying to use matlab script in labview to post process the sampled signals from DAQ(attached is the vi I tried)
After every 10 seconds I want to the send the sampled voltage data to matlab scritp block which does 1) detection of peaks using peakdetection function and plots the obtained peaks on the sampled signal 2) calculates standard of 10 secs data and plots on chart.
But I am confused of 1) how to call the peakdetection function inside the matlabscript block
2) How to send the 10secs data of voltage and time values to the matlab script block
3) How to plot the signal and detected peaks on the same plot (which can be done in matlab using holdon as shown in the atached vi).
Can someone suggest for implementing these .
Thanks.
Solved!
Go to Solution.
Attachments:
Labview&Matlab.vi 55 KB
Thanks GabeG,
Now, Labview&Matlab_TestNoAq.vi is woking Good and for the second one Labview&Matlab_TestAq.vi it is showing error as shown in the attached image when these ines of code are present in the matlab scrtip
subplot(2,1,1),plot(maxtab(:,1),maxtab(:,2),'*r');
SDN=std(maxtab(:,1));
and SDN output of the Matlab script
but when I removed these it is working fine(but not showing the detected peaks).
Can you suggest me a solution for the above and also can I know the best method to add one more channel that samples another device signal which has to be processed in this same way(Signals sampled from 2 devices have to be porcessed in this same way).
Thanks.
Attachments:
Script_Error.JPG 133 KB
Similar Messages
-
How to do complex engineering calculation in labview.I tried using MATLAB script
Hello,
I am trying to use matlab script node to solve two complex equation.But i get different errors everytime i run my program.sometimes 1048 sometimes 1050 and sometimes it says LABVIEW could not extract variable from Matlab.I am attaching my MATLAB script node with this thread.Please Help me out to get rid of this problem.
I am using LV-8 and MATLAB R-2006a.
Attachments:
matlab.vi 10 KBHi Praween,
beside my little MatLab knowledge I tried to replace your formula with equivalent LV code...
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome
Attachments:
matlab_lv80.vi 18 KB -
How to load a variable using MATLAB Script?
I need to load a selected variable from .mat file, using MATLAB script , and analyse it.
the attched shows my vi, there are two inputs nodes 'file' contains the .mat file path, and 'varn' contains varibale name in that .mat file which can be selected by user. Using " load(file)" the whole .mat file is loaded in the workspace and become avaiable at output node, however I am not able to pass a selected variable name through string "varn" input, MATLAB script does not recognize the variable.
any idea to reslove it is realy appreciated.
Attachments:
load a variable.JPG 18 KBDownload the VI and .MAT file. Run the VI, and it'll plot the data inside of the .MAT file.
Andy Chang
National Instruments
LabVIEW Control Design and Simulation
Attachments:
testfile.zip 5 KB -
Same code gives different results in Matlab Script in Labview and Matlab
I am implemeting a Matlab code into a LabVIEW application using Matlab script. When I import the exactly same code to the Matlab Script in LabVIEW it gives a different result than it is in Matlab. This code is a simulation code including first kind bessel functions. Using LabVIEW 7.1 and Matlab R14 service pack 3.
Labview 8.5
Matlab R2009b
Attached are the graphs produced by matlab script in labview and in matlab.
The minimum of graph produced by matlab code is below 1 and that in labview is above 1.
Thanks a lot for your reply.
Sorry, I haven't quantified the "sometimes" yet.
Attachments:
matlabsResult.jpg 29 KB
LV.png 84 KB -
Open a file using matlab script block
Hello!
I want to open a file from a specified directory using matlab script block.
The input of this block is a string with file's name......but it doesn't work in this way. I have to change the input data or I have to change it into matlab matlab script?
Some idea?
Thanks!
Attachments:
example.PNG 4 KBOoooppss!
My computer is crazy....sorry.
I'm near to solve my problem...
The problem is that I have a column of strings like this
str=['labview'
'labview2'
'labview3'
'labview4']
I use the double command but the byte array to string block only converts me an element, do you know is exist another block to change all the elements.
I've tried to do with a for loop block....using an index array and changing with i the index element, but it doen'st work.
You have some idea? -
Hello!
I'm using matlab script block in my aplication. The m-file (from matlab) contain an 'if' that depends of an input of labview.
I want to pass trough this condition only once when input's value changes, but labview "covert" this 'if' in a 'while' and pass trough this sequence n times.
How can I to impose to pass throug the sequence once the input's value change. It's better to specifie it from matab or from labview.
Thank you in adavanceWhat is surrounding the matlab script block? LabVIEW should be modifying the matlab code, it should be connecting with matlab and matlab executes its code, returning the results to LabVIEW. Can you do a screen capture of the part of the code that contains the matlab stuff? If yes make sure that it is saved as a .jpg (not .bmp!) for size reasons. If not, if you can send the part of your code that includes the matlab stuff that would help.
P.M.
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion -
Matlab script of labview keeps executing multiple times,
i have some code for serial communication in matlab , i want to use it in labview for easier and better gui design. for that i have used matlab script node in labview. it seems that labview keep executing the matlab script but i want labview to execute it only once.is there any way to do it?
Solved!
Go to Solution.i am attaching a vi file. this vi sends 'h' to the com1 continuously but i waant it to send only once.
Attachments:
forum.vi 7 KB -
Error (1046) using matlab script
Hi ,
im trying to use matlab script Labview , i've got matlab installed.
when im running the VI , i'm getting an error 1046 , i tried to search the community ,
and i've been told to check the "choose script server" , i dont know why , but i it's "grayed" ,
and i cant change anything.Cobmetal,
Looking at the following KnowledgeBase, it looks like MATLAB® may need to be registered as an ActiveX server first.
http://digital.ni.com/public.nsf/allkb/5BECAA32D63921628625670C005BDA1A?OpenDocument
Mathworks has good documentation about how to register MATLAB as a COM Automation server in the Windows registry when launched. I would try to do that if the option to choose script server is greyed out (Ctrl+F regserver).
http://www.mathworks.com/help/matlab/ref/matlabwindows.html
MATLAB® is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.
Matt J
Professional Googler and Kudo Addict
National Instruments -
Hi there,
I want to integrate my Matlab script in Labview,
the input variable should be a Matrix like
the following A = [ 0 256 ; 1 256 ;1.5 100 ; 1.55 110; 1.59 55; 1.6 56 ; 9 256; 14 256 ;15 100 ]
How do I do this in Labview, I tried an array but
no succes...
Bye for nowhi chris .. thanks for the reply ...
here's the results from 'ver
MATLAB Version 7.0.1.24704 (R14) Service Pack 1
MATLAB License Number: 227039
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 2)
Java VM Version: Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
MATLAB
Version 7.0.1 (R14SP1)
Simulink
Version 6.1 (R14SP1)
Aerospace
Blockset
Version 1.6.1 (R14SP1)
Bioinformatics
Toolbox
Version 1.1.1 (R14SP1)
CDMA Reference
Blockset
Version 1.1 (R14SP1)
Communications
Blockset
Version 3.0.1 (R14SP1)
Communications
Toolbox
Version 3.0.1 (R14SP1)
Control System
Toolbox
Version 6.1 (R14SP1)
Curve Fitting
Toolbox
Version 1.1.2 (R14SP1)
Data Acquisition
Toolbox
Version 2.5.1 (R14SP1)
Database
Toolbox
Version 3.0.1 (R14SP1)
Datafeed
Toolbox
Version 1.6 (R14SP1)
Embedded Target for Infineon C166 Microcontrollers Version 1.1.1 (R14SP1)
Embedded Target for Motorola
HC12
Version 1.1.1 (R14SP1)
Embedded Target for Motorola
MPC555
Version 2.0.1 (R14SP1)
Embedded Target for OSEK
VDX
Version 1.1.1 (R14SP1)
Embedded Target for TI C2000
DSP(tm)
Version 1.1.1 (R14SP1)
Embedded Target for TI C6000
DSP(tm)
Version 2.2.1 (R14SP1)
Excel
Link
Version 2.2.1 (R14SP1)
Extended Symbolic
Math
Version 3.1.1 (R14SP1)
Filter Design HDL
Coder
Version 1.1 (R14SP1)
Filter Design
Toolbox
Version 3.1 (R14SP1)
Financial Derivatives
Toolbox
Version 3.0.1 (R14SP1)
Financial Time Series
Toolbox
Version 2.1.1 (R14SP1)
Financial
Toolbox
Version 2.4.2 (R14SP1)
Fixed-Income
Toolbox
Version 1.1 (R14SP1)
Fixed-Point
Toolbox
Version 1.1 (R14SP1)
Fuzzy Logic
Toolbox
Version 2.2 (R14SP1) -
How to use matlab function with labview?
Hello,
I just want to use some matlab functions like floor(),ones()... in my labview code, who can tell me how to do it?
I want to only install MCR in my PC, so MATLAB script node can not work because it need matlab installed.
Thanks
Solved!
Go to Solution.floor() exists on the standard labview pallet already and the ones() function would be fairly simple to reproduce. If you only need a few basic functions repost asking for direction on recreating those specific methods. However, you're right - there is not a direct way to use compiled matlab code in labview without full matlab and the math script nodes. If you're really desparate to reuse some some exisiting IP there are C++ alternatives that implement many of the same methods and syntax as matlab (http://arma.sourceforge.net/faq.html). I'm fairly sure there are other tools that attempt to translate matlab code into pure c functions, both of which can be called via a DLL from within labview: https://decibel.ni.com/content/docs/DOC-9076
Alternatively, here is an all NI linear algebra solution: http://sine.ni.com/nips/cds/view/p/lang/en/nid/210525 -
Creating a random noise (Gaussian) using Matlab Script
Hello,
Since I only have Labview 6.1 base, I can't use the white-noise generator in Labview. I'm thinking of using the Matlab Script. I have Matlab 2006R installed in the same computer. However, I tried running the program and nothing happened (I used the help example "a=rand(50);surf(a)" in the Matlab Script.
Why it's not calling the Matlab, or is there a better way to create a Gaussian distribution in Labview 6.1 Base?
Thanks a lot!Hello,
Why are you unable to use the Gaussian White Noise VI in LabVIEW 6.1? It is under the Analyze >> Signal Processing >> Signal Generation palette. I have attached a simple VI that illustrates creating a matrix.
If you wish to use the MATLAB® script node, let's first make sure it is working correctly. Try opening one of the LabVIEW shipping examples. Browse to <LabVIEW>\examples\scriptnode and open "HiQMATLAB_Fractal.llb." Then open "MATLAB Fractal.vi." Run the VI. Do you get any error windows that pop up? If not and you see a picture of a fractal appear, then the connection to the MATLAB software is working correctly. In your VI, try creating an error out indicator from the MATLAB script node and see if any errors appear.
If you do see an error in the shipping example, it means there is a problem with the software connection. Make sure that you have launched the MATLAB software at least once after you installed it. This will set up the necessary connection information. Then launch LabVIEW. If this isn't the issue, we could try manually restoring the server commands. Make sure LabVIEW and the MATLAB software are not running. Go to a command prompt, browse to the MATLAB bin directory (e.g. MATLAB\R2006b\bin), and type
matlab -regserver
Quit the instance of the MATLAB software that appears and launch LabVIEW. If this also fails, please post again with any error information you receive.
Also, the rand function in your script will not generate a Gaussian distribution. You will need to use the randn function instead.
MATLAB® is a registered trademark of The MathWorks, Inc.
Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
Edit: For some reason, I am unable to attach the VI. I have included a picture instead.
Message Edited by GrantM on 08-08-2008 02:50 PM
Attachments:
Gaussian Matrix.png 35 KB -
Hi,
I have never used LabVIEW and I am wondering if there is a way to run Matlab code in LabVIEW. If so, how would I do it and are there any special instructions or tips I should know about?What is your LabVIEW version?
Do you have matlab installed on your computer?
In older LabVIEW versions, you can only use the matlab script node, which requires that you have a copy of matlab installed.
In newer versions, you have two more alternatives that don't require the purchase of Matlab:
Use a mathscript node.
Use a scilab script node.
Information on mathscript: http://zone.ni.com/devzone/cda/tut/p/id/3502
Information on scilab: http://zone.ni.com/devzone/cda/epd/p/id/657
There is even a mathscript forum here: http://forums.ni.com/ni/board?board.id=MathScript
LabVIEW Champion . Do more with less code and in less time . -
Please help me out...
Solved!
Go to Solution.bombay wrote:
Yes. It can be done. But Math script can not evaluate all functions in .m files (There are some exceptions).
And those can perhaps easily be ported to LabVIEW/MathScript?
It is not sufficient to disregard running your Matlab code in LabVIEW based on a few exceptions without first thoroughly evaluating the impact they have.
If you want to stick with Matlab in your implementation, then there are other avenues than hypotethizing about the limited portability issues of using MathScript in your project?
Br,
/Roger -
Hello!
I'm using a matlab script block and I have a problem that i don't how to solve it,
I want to import a column that in matlab is cell array or char array type. When you create an output in matlab script block you have to specify the data type....I choose string, but with this option you can only import one string....and I want to import a whole column.
Someone knows how I have to do to import this data type? I have to do some changes to the data from matlab or I have to use some especific block in labview to adapt the data.
Please help me!!
Thanks!!!Ooooppss!
My computer is crazy....sorry.
I'm near to solve my problem...
The problem is that I have a column of strings like this
str=['labview'
'labview2'
'labview3'
'labview4']
I use the double command but the byte array to string block only converts me an element, do you know is exist another block to change all the elements.
I've tried to do with a for loop block....using an index array and changing with i the index element, but it doen'st work.
You have some idea? -
Possible threadsafe issues using Matlab scripts?
Hi all,
I'm developing an application in Labview 6.1 that makes extensive use
of Matlab scripts. The application executes the same set of
scripts for multiple data sources, and keeps track of the inputs and
outputs for each data source separately. I've been noticing that
the application produces the correct results when running only one data
source, but that the results are often incorrect when I run it against
multiple data sources.
I've done some investigation, and have found that all Matlab scripts
share a common memory workspace in Matlab. That is to say that if
I have ScriptA that takes variable X as an input, and ScriptB that does
not, ScriptB nonetheless has access to variable X in its workspace
(from the last time ScriptA was called). This doesn't pose a
problem to me directly, but it has made me wonder if there are
potential threading issues in the scripts.
Consider the following scenario with one script and two data
sources. I'm wondering if this scenario is possible in Labview:
1. Thread1 calls ScriptA, passing data from SourceX.
2. During Matlab execution (somewhere in the middle), Thread1 is suspended.
3. Thread2 calls ScriptA, passing data from SourceY (data have the same variable names, since it's the same script).
4. Thread2 finishes ScriptA execution uninterrupted with SourceY data.
5. Thread1 is reactivated, but now the Matlab workspace data has
been replaced with SourceY. So, Thread1 started with SourceX
data, but finished with SourceY data.
6. An incorrect result for Thread1 is produced, because the wrong data was processed.
Clearly I could get around this problem with a semaphore, but first I'd
like to know if this scenario can even happen. Are Matlab scripts
treated as atomic operations in Labview, or can the threads be
suspended midway through execution?
Thanks for your help!
cjbHello,
No. LabVIEW will definitely not compile a VI while it's running - I think that would be, even conceptually, impossible. In fact, some properties (accessed via property nodes) are not editable at run-time for basically that reason, that a recompile would be necessary in order for the affect to take place, and the recompile can't take place at run-time!
It is indeed strange behavior, particularly because it is intermittent (which does hint at a threading issue, or some factor outside the development environment). Can you try moving the initialization to LabVIEW? I have attached an example of a so-called functional global variable (a simple code module in this case). It has two "states" (which are cases) - one is initialize and the other is the "usually executing case." The initialize case is used to initialize the shift register to an array of 50 doubles, where the other case will compute the running average, min, and max across the 50 most recent random numbers generated. The 50 data point code module.vi is the code module, and it is called by Use 50 data point code module.vi. When you run Use 50 data point code module.vi, be sure to toggle the initialize boolean so that the initialize case executes once to allocate and initialize an array with 50 elements; when you toggle it back then it will execute the other case on each iteration, and begin computing the statistics noted by keeping an array with the 50 most recent random data points generated.
I hope this helps and that you are able to incorporate a similar code module into your application to avoid the intermittent errant behavior!
Best Regards, and feel free to post again with updates!
JLS
Best,
JLS
Sixclear
Attachments:
Use 50 data point code module.zip 27 KB
Maybe you are looking for
-
Refreshing a variable in a procedure
Hi! I know such thread has been already posted many times, but I do everything as explained and it still doesn't work. I have created variable STARTDATE: TEXT, Latest Value and a package with following steps: 1) Declare Variable STARTDATE 2) Refresh
-
Why is the CPU usage different ? I used LOAD_BALANCE option.
I used a oracle 11.2.0.2 in RAC 2 nodes. And I used LOAD_BALANCE option in the WAS pool configuration jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.118)(PORT=1522))(*LOAD_BALANCE=YES*)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_
-
Help! how to refresh the JTable of a class from another thread class
there is an application, in server side ,there are two classes, one is a class called face class that screen a JTable, another is a class the a thread ,which accept socket from client, when it accept the client socket, it deal the data and insert int
-
Hy people! i have one doubt! i have a xml that have 10 purchase orders. i use this command to get duplicated purchase orders <?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,var,1)?> . In layout i have 20 purchase orders. the first 10 are the ori
-
can some one please help with this error