Using array as a MATLAB script input in a subVI - labview crashes

Hello
I am having troubles in creating a subVI that includes a matlab file which has an array as an input.
I have created a VI, that executes a simple matlab script, having an array as an input and an array as an output. This worked fine, untill i assigned the terminals in order to use it as a subVI.
After the terminals have been assigned, labview instantly crashes when running the file.
I also created a VI to test the subVI, but I couldn't get it to work at all, labview always crashed...
Does anyone know a solution to my problem? They only thing i can think of is to not use it as a subVI, but then my main file will get huge, as all the matlab code would be included in there...
attached are both files, so that you better understand my problem. (test_... is the main file)
any help will be greatly appreciated!
- Jarno
edit: I'm using labview 2013 with windows 7 and matlab 2014
Solved!
Go to Solution.
Attachments:
test_subVI_array_into_script.vi ‏8 KB
subVI_array_into_script.vi ‏8 KB

Hey Jarno, 
I did some playing around with this (sorry for the delay) and another workaround we can use is adding an Always Copy to the array before passing it into the Script Node. This will allow you to continue using Double precision arrays instead of going to Singles.
It looks like there is an issue with the array copy that is passed into the SubVI through the terminal, but we can get around it by making a new copy that the Script Node can properly work with. 
Tim A.
National Instruments

Similar Messages

  • Matlab Script Inputs

    I'm trying to run the example file "MATLAB Script - Lorenz Diff Eq.vi" and get the following error. Any idea why?
    Error 1047 occurred at LabVIEW: LabVIEW failed to send variable to the script server.
    Server:"Inappropriate input array sizeE" in MATLAB Script - Lorenz Diff Eq.vi
    Possible reason(s):
    LabVIEW: LabVIEW failed to send variable to the script server.
    Also, when I run the example code from the help file in a separate vi:
    a=rand(50)
    surf(a)
    it works fine, but when I add inputs and outputs to the same script, the inputs and outputs work, but it never draws the surface 'a' or seems to update 'a'.
    Thanks for your help!
    Attachments:
    matlabtest.vi ‏14 KB

    Alejandro,
    Thanks for your help. When I run the sample code for the rand() and surf() functions, Matlab runs the code properly, opens a new figure to display it, updates dynamically and even outputs the variable 'a' back to Labview correctly.
    So, outputs seem to work fine, but I haven't been able to get any inputs to work. So that leads me to believe that the Matlab server is working (as it can crunch code and send back data), but perhaps it's not enabled to take an input or I'm trying to pass the input improperly.
    Is there any trick to send an input to Matlab? In other words, if I send a constant, for example, the number '2' to Matlab, I wire a constant '2' to the input on the Matlab VI block and then set the data type as 'Real', and I get the
    error.
    Does the error have to do with the array size (as it claims, even though I'm trying to pass in a single real constant, not an array...), or is it really a communication error as you suggest? Thanks for your help!
    Neville

  • Error 1050 by trying to use load'filename' in matlab script node

    Hi
    I keep getting error 1050 when Labview tries to load a text file through the matlab script node.
    I've all ready checked for it on google and this forum but found nothing. I've also done this: http://digital.ni.com/public.nsf/allkb/2B3FF46C8512C4F786256CF30071BE53 and tried to use dlmread and more. 
    The thing is that  I need the matlab script node to read a txt file that Labview made from a chart with only 1 array, plot it and export a jpg image. I can't really use the 'export image' or 'get image' function in Labview cause I need the whole plotted chart (these functions only take a snap shot of it when they're run).
    This is my code that I'm using:
     data=load('file') ;
    Vpp=(data(1:2000,1));
    xsize = (1/2000);
    plot(0.0005:0.0005:1,Vpp);
    axis([0 1 -5 5]);
    print('-djpeg', 'graph.jpg');
    The usual load in matlab to load txt files and print to print the jpeg. The code works in matlab but not in labview
    And yeah, I'm using windows 7 and legal versions of matlab r2009b and Labview 2009  
    Solved!
    Go to Solution.
    Attachments:
    matlab.jpg ‏213 KB

    Yes I forgot, this is my error...  It looks like it can't read the file path, but the 'file' path is actually just a path to my c:\user\*\*\*\*.txt 
    Error 1050 occurred at LabVIEW:  Error occurred while executing script. Error message from server: ??? Error using ==> load
    Unable to read file file: No such file or directory.

  • Outputting of of a Matlab Script

    Hello everybody
    I am working on a project for school and had a question as far as outputting out of a Matlab Script node. I have data that is stored in the form T(:,:,i) so it is a 3D data that is calculated within the the script. 
    The main thing I am wanting to do is output the data so I can graph it on a Labview front panel. I want to display a 2d image with a third dimension respresented as points on that 2d image. (2d as space with 3rd dimension being temperature).
    It may not make sense why I am doing this in Labview but I have an entire GUI built for Labview and this is just one snippet of the things that I want to show. I included a file for the particular graphs I am trying to ultimately display. 
    I apologize I am still learning the ropes to Labview.
    Solved!
    Go to Solution.
    Attachments:
    PowerSimForForum.vi ‏11 KB

    Hi Jakeyboy1,
    Below is a link that demonstrates how to send a 3-Dimensional array from LabVIEW, however you should easily be able to modify the block diagram in the article to switch the processes.  In the article, the example code first auto-indexes a 3D array to assign T(:,:,i) within the script environment.  Then LabVIEW uses another script node to process the built 3-Dimensional array.
    You can switch this process.  Out of the first script node wire out the length of the 3rd dimension and feed that into the N terminal of a for loop.  Within the for loop place the script node which reads T(:,:,i) and outputs the 2D array from the node.  You can wire this out of for loop and autoindexing should creat the 3D array in LabVIEW.  Since the N terminal matches the length of the 3rd dimension.  The resulting array in LabVIEW should be identical.
    Send N-Dimensional Arrays into a MATLAB® Script Node
    Regards,
    Isaac S.
    Applications Engineer
    National Instruments

  • Insert of Matlab script

    Hi all, I am new to Labview and need some help in doing my project. I know that Matlab script can be written in Labview and would like to know the procedures. Does anyone has any examples or tutorial on this? Thanks in advance
    Rgds,
    Tay

    Hi Tay,
    If you want to include MATLAB script directly in your VIs, you will need to use the MATLAB Script Node, found in the Mathematics > Scripts and Formulas > Script Nodes palette in LabVIEW 8.0.  There are also some MATLAB Script Node examples in your LabVIEW directory...specifically, the examples\scriptnode folder.  And of course, if you search the LabVIEW Help for "MATLAB Script Node" you should find some helpful documentation on the subject.
    Also, if you're using LabVIEW 8.0, you should try out the MathScript Node, which is similar to the MATLAB Script Node, except with MathScript, all of the work is being done in LabVIEW...MATLAB is not required.
    Good luck,
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Input data type of Matlab script node

    Hi,
    I have 1D array of complex number in single precision.
    Matlab script node is used to import data into Matlab and do some data processing, and then export.
    Data type of input is currently double precision.
    How to re-define this input data type of the Matlab script node?
    Thanks,

    Right, arrays of singles are not supported. See Comparison of MathScript RT Module and the MATLAB® Software Data Types in LabVIEW
    As for memory usage, Profiling the VI should let you know how much memory Labview uses when running your code. Communication with MATLAB® is done through ActiveX, and I'm actually not 100% sure whether it will reflect memory usage from script execution. I think it'll be simple enough to profile your VI with and without the MATLAB Script node and note the memory usage difference...
    Misha

  • 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 KB

    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?

  • Using a 3D matrix with a matlab script block

    Hi all of you,
    it is possible to input a 3D matrix (e.g. 10x4x20) to a matlab script block or you have to unfold this data in a 2D array?
    Do you know what i have to do to input directly a 3D array (array of real numbers) to a matlab script block.
    P.D.; I'm using labview 7.0 and matlab 6.5
    Thank you very much
    Larson

    Hi,
    as far as I know there is only the possibility to have an input for a
    2D array to matlab scriptnode. Thus you should convert your 3D data to
    2D in LV and reconvert it in your matlab code into 3D.
    When you select 3D data as an output of a script node it automatically
    appears as 2D (but no data will be lost). So when you have to use it in
    LV again as 3D data, what you have to do is reconvert it back from 2D
    to 3D.
    Hope this helps!

  • 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!
    cjb

    Hello,
    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

  • 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 KB

    Download 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

  • Using matlab script

    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 adavance 

    What 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

  • Using matlab script block

    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?

  • Sending time and voltage samples as input to matlab script block

    Hello,
    I am planning to use Matlab script in labview and the matlab scritp block needs inputs of time and voltage values of sampled signal to post process.
    Can someone explain me of how to send the sampled values of time and volatge after every  'x' interval of time to the matlab scritp block I mean if the sampling rate is 100Hz then 100samples will be collected in 1 sec but I want to send both time and votlage values collected after every 10 seconds to the matlab scritp block.
    Thanks.

    Hi,
    I am using DAQUnit 6016 that samples an analog signal of sensor.The vi I tried is attached below.
    Attachments:
    Labview&Matlab.vi ‏55 KB

  • Using '!' in matlab script

    It seems unable to invoke the '.EXE' file in the matlab script node.
    In my matlab code I use '!' to invoke a .exe file, it can be execute in matlab, but when I copy the same code to labview(matlab script node), it does not work
    the error messages are
    LabVIEW:  Error occurred while executing script. Error message from server: Warning: Name is nonexistent or not a directory: D:\Wastewater_experiment\programCodes\DymolaFiles.
    > In c:\matlab6p5\toolbox\matlab\general\path.m at line 116
      In c:\matlab6p5\toolbox\matlab\general\addpath.m at line 88
    < c:\matlab6p5\bin\win32\dsu.txt created.
    ... Error message from alist
    Error opening file "dsin.txt": No such file or directory
    ??? Error using ==> load
    Unable to read MAT file temp.mat: not a binary MAT file.
    Try LOAD -ASCII to read as text.
    Error in ==> C:\dn\programCodes\initload.m
    On line 43  ==>      load temp
    Error in ==> C:\dn\programCodes\operatingPoint.m
    On line 17  ==> [x_init, x_name] = initload; % loads initial conditions from txt-file 'dsin.txt'.
    . in labviewmatlab.vi
    I am sure I have add all the path. and If I just run the code
    ! alist -a dsin.txt dsintest.mat
    in matlab script node. There is no errors but it can not be execute.
    This alist.exe file is from 'Dymola' to transfer the 'txt' to 'mat'.
    How can I do with this error
    Attachments:
    labviewmatlab.zip ‏52 KB

    Sorry
    The problem have solved.
    When I invoke .txt .mat .exe in LabVIEW matlab script node, this files should be under '.../matlab' path. I do not kown why it is not '.../matlab/work'.And 'addpath' is useless except to 'invoke .m' files.
    It can work now.

  • How to use Array in Calc script.

    Hi, <BR> I want to use Array in Calc scripts. Can anyone provide me some examples. <BR><BR>Thanks<BR>Murali

    For information on the ARRAY command, check out <a target=_blank class=ftalternatingbarlinklarge href="http://dev.hyperion.com/techdocs/essbase/essbase_712/Docs/techref/techref.htm">this hyperlink</a>.<BR><BR>Click on <b>Calculation Commands</b>, then choose <b>ARRAY</b>.<BR><BR>Can you give me some information explaining why you want to use ARRAY? It's use is pretty rare and I would like to understand what you're trying to do.

Maybe you are looking for