Changing a path dynamically in a MathScript node

I have inherited a MatLab script that must be run in LabView. The first issue I have is creating unique paths. When a Unit Under Test runs, its data will be saved to a file based on the serial number of the UUT. The MatLab script then analyzes the data from that file and creates a new file based on the serial number with a new file extension. Therefore, I need to read in a file whose path changes and write a file whose path changes. The relative path will be the same but the unique file will not. I am looking for suggestions on how to do this since there will be hundreds of serial numbers being tested. It would be nice if the node could have an input that could configure to a path or string type instead of a scalar only. The serial numbers will be apha-numeric and this must be able to exist as a stand alone application.
Also, the node reports a 'unexpected token: function'. I am noticing that functions must be a seperate .m file but how do you call the function after that?
I am using LV 8.5
Thanks - Jeff
Message Edited by j.masse on 07-07-2008 07:57 AM

Hello Jeff,
Creating unique paths is not difficult in MathScript.  Simply pass in the string you want to use as the specific part of the path and have a local variable contain the base path.  For example, if you have a string input named serial to the MathScript node, the following code will build a path:
basepath = 'c:\data\';
filename = [basepath serial];
You mention needing to do this for a large number of files.  The easiest way to do this is to have your loop in LabVIEW and simply pass in one string at a time to the MathScript node to do your processing.  If there is a lot of setup work involved before the work that needs to be done for each file, then it is more complicated.  There really isn't a concept of an array of strings in the language.  The closest you can get is a cell array containing many 1D character arrays.  However, LabVIEW MathScript does not yet support this construct.
You can pass in a LabVIEW 1D string array -- the MathScript node input will adapt to the type wired to it.  What it does is create a 2D character array in MathScript.  If not all the strings are the same length, then it will pad the end of the string with zeros.  This presents a problem when you try to use the string as a filename.  However, you can use the strrep (string replace) function to replace the zeros with empty strings.  For example, assuming you have an input variable named serial that is a 1D array of strings and a loop-control variable named index, type
basepath = 'c:\data\';
name = strrep(serial(index, : ), char(0), '');
filename = [basepath name];
You cannot write a function inside of a MathScript node.  What you can do is create a .m file on disk and add the directory to your MathScript search path.  The default search path is your "My Documents\LabVIEW Data" directory.  But if you add the file elsewhere, there are three ways to set the search path for MathScript.  First, from the MathScript Window, go to "File >> LabVIEW MathScript Properties" and click on the "MathScript: Search Paths" category item.  This will set the search path for the MathScript Window only.  Second, from a LabVIEW VI, go to Tools >> Options and click on the "MathScript: Search Paths" category item.  This will set the search path for all VIs in the main application instance only.  Third, from within the project explorer, right-click on "My Computer" and select Properties.  Then click on the "MathScript: Search Paths" category item.  This will set the search path for that context only.  Since you are talking about using this in a built application, the third option will likely be what you need.
As for using a built application generally, as long as you avoid any MathScript function that describes itself as being unsupported in the run-time engine, you should be okay.  The help for individual functions will list if they are unsupported.  You can see a list of all such functions by looking in the LabVIEW help index for "MathScript" and double-clicking on the entry for "functions not supported in Run-Time Engine."
Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments

Similar Messages

  • Dynamically loading the MathScript Node

    Hi - Is it possible to dynamically load script into the Mathscript Node at Run time. I see that you can use define functions and paths and things . But being a newbie to Mathscript could all this hang together to make dynamic loading a possibility and how?
    thanks dht 

    Hi,
      unfortunately the node doesn't support run-time dynamic loading of scripts. You can load variable values with the load function, but not scripts.
    http://zone.ni.com/reference/en-XX/help/371361A-01/lvtextmath/msfunc_load/
    http://zone.ni.com/reference/en-XX/help/371361A-01/lvhowto/saving_loading_scripts/
    Depending on your application, you could use a case statement to decide between several pre-built (and possibly compiled) mathscript nodes, and acheive the functionality that way.
    Another option might be to use the formula vi's instead, although this will require a more complex architecture to parse the text file you'd generate.
    For more information on MathScript, please see the following link
    http://zone.ni.com/devzone/devzoneweb.nsf/Opendoc?openagent&568C773718B080F286257096005BD314
    Hope that helps
    Sacha Emery
    National Instruments (UK)
    // it takes almost no time to rate an answer

  • Change directory path dynamically using UTL_FILE

    I have a directory TEST_DIR which points to /test/files/
    CREATE OR REPLACE PROCEDURE file_exist (v_country in varchar2) is
    v_check_file_exist BOOLEAN;
    v_dir VARCHAR2 (256) := 'TEST_DIR';
    begin
    UTL_FILE.fgetattr (V_DIR || V_COUNTRY,'file123' ||'.txt', v_check_file_exist, v_a,v_b);
    IF NOT v_check_file_exist THEN
    DBMS_OUTPUT.put_line (TO_CHAR(from_date,'YYYYMMDD')||'.rds');
    END IF;
    END LOOP;
    I would like to change the directory path based on the country which is passed as input to the procedure
    exec file_exist('IND'), so in this case I want the procedure to look for file 'file123.txt' under path /test/files/IND.
    But this is not working..
    But when I change the directory to
    create or replace directory TESTDIR as '/test/files/IND' and then change my UTL_FILE.fgetattr (V_DIR,'file123' ||'.txt', v_check_file_exist, v_a,v_b)(removing || v_country, this time it works.
    am trying this as I have many country folders under the path like
    /test/files/IND
    /test/files/USA
    /test/files/AFR
    and want to change the direcotry path dynamically according to input given.
    Any suggestions

    Make sure that the directories you are trying to write to have been set up for UTL_FILE.
    Refer to UTL_FILE_DIR parameter or CREATE DIRECTORY privilege depending on what DB version you are on.
    HTH
    --Johnnie                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to change the images dynamically in a table.

    Hai,
                     How to change the images dynamically in a table based on the condition in webdynpro abap.
    Edited by: Ravi.Seela on Oct 13, 2011 2:17 PM

    This has been much discussed earlier. Do search posts.
    For your scenario i would do the following.
    inside your node which is binded to the table, i create a new node image with cardinality 1 ..1 and a attribute called path of type string.
    create a  supply function for the node image .
    Supply method now has a Element (Parent element ) and node.
    Based on your record in element, set the right image source to path attribute and bind the node.
    This will make sure that the framework calls the image supply function for every row in a table.

  • Is it possible to define a function in the MathScript Node

    Is it possible to define a function in the MathScript Node

    You can not define a function inside of a MathScript Node, but only because it isn't necessary. The way custom functions work in MathScript is that they are saved in .m files located in paths in the MathScript path list. When the MathScript compiler receives a function that it doesn't recognize, then it searches for it in the path list, and upon finding it, compiles and loads the function. You can specify these search paths manually by going to File>>MathScript Preferences from the MathScript Window or dynamically by using the path() command within a script.
    To answer your original question, if you would like to create custom functions dynamically within a VI, then you can simply build your custom functions using strings and then save them to an ASCII file with the extension .m. You could either save the file to a path already in the MathScript path list or you could dynamically specify the path by passing the path into a MathScript Node as a string and by using the path() command at the beginning of your script to set it.
    Kind Regards,
    E. Sulzer
    Applications Engineer
    National Instruments

  • Calling a .m file from inside a mathscript node

    hello all i am hoping someone can help me out, I am in the process of converting our version 7.11 matlab node vi's to mathscript (I hope) AND I HAVE RUN INTO AN ISSUE. we have a very simple matlab script that bundled the data and sent it to another matlab sub routine. when i copy this script over to mathscript I get the following eror: Unknown symbol on line 13: Pre_Process_Function_Pulse. Is there a way I can call and run these subroutines from the mathscript node? Do i need to convert the sub routines into a mathscript file? or do i just need to change the syntax for my call? bmp of the offending line in mathscript attached. please forgive if this is an easy question, I am not really a matlab programmer, the files that we are running are provided from elsewhere, and i get to integrate them any and all help is always appreciated thanks Chris
    Attachments:
    mathscript.JPG ‏51 KB

    Hello again,
    Ok I am still having issues running the matlab script in mathscript.  I have gone back to the original scripts with all the nested sup routines.  and the mathscript code is just a call to the first .m file subroutine.  but for some reason mathscript will not recognize the function call as a call?  I recreated the original matlab node in a sequence, so the matlab node runs (successfully) and then the next sequence is the identical call in mathscript.  I have set the path in mathscript to the directory where all the .m files are located.  The pre-process_function_pulse .m file sequentially calls 6 very small .m subroutine files.  all are located in the same directory.  and this directory is the only one listed under path and working directory in Mathscript preferences.  Additionally from the last suggestions all traces of the original japanese comments have been deleted from all the .m files.  The inputs and outputs are the same for the matlab and mathscript nodes.  so i am basically at a loss here.
    Any and all help will be greatly appreciated.
    thank you
    Chris
    Attachments:
    mathscript.doc ‏138 KB

  • How to pass the "path" dynamically to KM navigation iView ?

    HI Experts.
    This is my issue:
    I have a WD Java iView, with a data table.
    In the same page, I have a KM navigation iview too.
    Conceptually, each row in this table, have some documents in a CM Repository asociated.
    This repository has subfolders for each master data in the table.
    (example: imagine a table with material master data, and a repository with a subfolder for each material,
    and inside of it, several unstructure documents about this material.
    Then, I need to call a KM Navigation iview when click a table row, passing parameters, in special the "path".
    I am using this code in my action (triggered from webdynpro iview)
         WDPortalNavigation.navigateAbsolute("ROLES://portal_content/com.stk.demos.folders.zz_demos/com.stk.demo.ch.TEST_CH/com.stk.demo.ch.Listar_Docs",
         WDPortalNavigationMode.SHOW_EXTERNAL, (String)null, (String)null,
         WDPortalNavigationHistoryMode.ALLOW_DUPLICATIONS, "test",
         (String)null, (String)null );
    Partially it works, the window open and show the navigation iview, but...
    in the root directory (or directory indicated in iView harcoded properties);
    But I need pass the path !
    How can I call that iView, dinamically using a parameter, the path (property ID: path)
    to the KM navigation iView, in order to open initially in a indicated path?)
    I have read this link
    http://help.sap.com/saphelp_nw04s/helpdata/en/c3/235a428a1e9041e10000000a1550b0/frameset.htm
    but, I still can't understand how to use this parameters.
    Thanks in Advance.
    Leandro.

    Hi Leandro,
    You can create your own proxy IView and then redirect it to KM Navigation IView.
    This way you can dynamically change the path.
    Check this to know about proxy IView:
    KM Document Iview Source Code
    /thread/190600 [original link is broken]
    Regards,
    Praveen Gudapati

  • Changing physical path in FILE TCODE using ABAP CODE

    Hi all ,
    I want to change physical path linked to logical path in TCODE FILE dynamically using ABAP program. Is it possible.
    If yes then how?
    Thanks for your help.
    Regards,
    Uday.

    s

  • How to call User defined functions in Mathscript Node ?

    Hi,
    I have created a user defined function and saved it to Search path of Labview as an M file. If I run my program in Math script window, the function is recognized and the program works properly. If I do the same with MathScript node , the user defined functions are not identified.
    Kindly help me with this problem. Thanks in advance
    Cheers
    Lenord Melvix

    This page may help:
    http://zone.ni.com/reference/en-XX/help/373123C-01/lvtextmathmain/caveats_recommendations_ms_search_...
    Kevin C.

  • How to implement a user-defined function in a mathscript node

    I am trying to use a mathscript node that includes self-defined functions, but I always get an error. I tried to run an NI-example: MathScript using Riemann Zeta.vi ,and I got the same error I get when I run my own programmes:MathScript Node'MathScript Node' (zeta): User-defined function contains an error. I didn't change anything in that example, so what could be wrong?

    Try the Mathscript forum instead. Good luck.
    (Maybe start reading this, for example)
    Message Edited by altenbach on 11-18-2009 01:48 PM
    LabVIEW Champion . Do more with less code and in less time .

  • Mathscript node errors due to not being able to find .m files

    I recently installed LV 8.5.1 and tried to open a VI with a mathscript node (originally created with LV 8.2).  It got a broken arrow due to an unrecognized symbol in the node which was the name of a matscript function in a .m file of the same name.  And this worked fine with 8.2.  I updated the mathscript: search paths 'Working Directory' both in the mathscript window and the main app Tools->Options list.  I exited and re-started, but to no avail.  And I made sure to add it as a 'recursive' search folder, even though my file is right at the top.
    What am I doing wrong?

    Hello Umars,
    In LabVIEW 8.5 you won't be able to use user defined functions if you are you using a Base Package.  Regardless of which package you are using you may find the LabVIEW help file informative.
    Calling User-Defined Functions from LabVIEW MathScript (Windows, Not in Base Package)
    http://zone.ni.com/reference/en-XX/help/371361D-01/lvconcepts/calling_udf/ 
    David A
    National Instruments
    FlexRIO Product Support Engineer

  • EXE I built unable to open reference to VI with MathScript Node in it

    Hi Everyone,
    First off, I'm using Labview 8.5 on Windows XP.
    I have two VIs. One called "Main Instance.vi" and the other is called "code.vi". The Main Instance vi is very simple. It opens a reference to code.vi. Using this reference, it dynamically calls code.vi using the "Call by Reference" node.
    The code.vi is also fairly simple. On this VI's connector pane, I have two inputs "a" and "b" and one output "c". All are of double data type. These controls are wired to a MathScript Node where the code inside is simply:
    c = a + b;
    So the idea here is that I am using the Main Instance VI to dynamically call and pass two numbers to code.vi. code.vi adds these two numbers via MathScript and returns the answer back to the Main Instance VI.
    This all works fine and dandy within LabView. However, when I build Main Instance.VI as an application, I am no longer able to open a reference to my code.vi because it has a MathScript Node in it. I put error indicators on the front panel of Main Instance VI to monitor the Open reference and Call by Refernce nodes. As VIs running in Labview, I get no errors and everything works fine ("a" and "b" are added and "c" is the correct answer). When Main Instance is an exe I get errors 1003 for the open reference function.
    I have attached screenshots of the Vis as well as the VIs themselves.
    Any guidance is appreciated. Keep in mind that I have to use Labview 8.5 as this is just an example of a bigger problem that is occuring in our software while developing a solution for a customer. Right now our software is compiled in Labview 8.5.   
    Attachments:
    Main Instance.vi ‏15 KB
    code.vi ‏30 KB

    Hello,
    As you may know, MathScript is implemented on top of LabVIEW.  Consequently, there are various VIs and controls from LabVIEW's vi.lib directory that are needed for a MathScript VI to run.  A built application can run on a computer that does not have LabVIEW installed.  The LabVIEW Run-Time Engine provides support for LabVIEW's primitives, but any functionality implemented in a VI must be included in the built application.  Otherwise, the application cannot find those support VIs. 
    Basically, the problem is that in trying to run your MathScript VI, you are only giving the application the top-level VI and none of the subVIs.  A way that will likely work around this is to build a source distribution with your MathScript VI.  Create a project with your VI in it.  Create a new source distribution build specification in the normal manner.  (I don't have LabVIEW 8.5 installed at the moment, but these are instructions for 8.6)  In the "Additional Exclusions" section, uncheck the "Exclude files from vi.lib" setting.  This should pull in all the subVIs you need to run the VI.  Then, open your top-level VI from your built application.
    Grant M.
    Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments

  • Getting -90031 (can't find function) error from Mathscript node when running executable, but works when I run the pre-compiled VI

    I have set the Mathscript preferences 'Path' and 'Working Directory' parameters to the folder containing my scripts, and it works when
    I run the VI, but I get a -90031 error when I run the executable.
    What am I doing wrong?

    Hi Umars,
    I had the same problem. In my case it turned out that it was caused the surrounding code. Plus the error
    message was missleading. I got the error message -90031 (unknown symbol CalcWelchCorr2) for the
    following piece of code:
    ecorr= 1;
    if setup & src== 1
       for lag= 1:50
       rho=  CalcWelchCorr2( lag, win );
       if rho > 0.001, ecorr= [ecorr; rho]; else, break; end
    end
    CalcWelchCorr2 is a user defined function located in the MS search path. The problem was caused by the
    "break" in line 5. Actually this line was marked by some little warning symbol. Eventualle I modified the code
    to get rid of the break
    ecorr= 1;
    if setup & src== 1
       lag= 1; rho=  CalcWelchCorr2( lag, win );
       while rho > 0.001 && lag <= 50
          ecorr= [ecorr; rho];
          lag= lag+ 1; rho= CalcWelchCorr2( lag, win );
       end
    end
    and voila, the executable worked fine.
    However, I had to check all my VIs ( > 200 !) for similar errors which gave me headaches.
    Why does the application builder doesn't produce some appropriate error message ?
    E.g. "Line xxx in MathScript node in VI xxx cannot be executed"? Currently you get the
    impression that the application was build successfully but eventually you get strange errors
    or even erroneous results. Keep in mind that tracking down bugs in the final application is
    much more difficult that in LV. Also the error message produced by the executable was not
    helpfull at all.

  • I want to load Firefox on my computer at home, which is not connected to the internet. I want to download Firefox to my flashdrive and then add it to my computer at home. When I try to download Firefox, it won't let me change the path of where it download

    I want to download Firefox on a flashdrive so I can then download it to my home computer which is not connected to the internet. When I download Firefox, it won't let me change the path and so tries to download on a public computer, which isn't allowed. The reason I want it on my home computer is because I'm creating web pages and I want to view my html pages using a variety of browsers, including Firefox.

    From another computer, go to http://www.mozilla.com/firefox/, click "Free download" button, click "Save File" button, select your flash drive in "Save as" window. "Firefox Setup 3.6.13.exe" file will be saved in your flash drive.
    You just need to insert it in your new computer and double-click on "Firefox Setup 3.6.13.exe" from Windows Explorer and follow instructions.

  • How to calculate the Percent change in a dynamic

    hi All,
    I'm trying to get the percent increase/change of two dynamic
    colums.  In my report, the user has a checkbox where he can select two colums to calculate the percent growth.
    My DataSet is PilarName, Calification(is a decimal value) and Period (this is a string).  I created the Matrix this way:
    PilarName [Period]
    [PilarName] [Calification]
    Which give me these values:
    So, now I need to create another column to calculate the percentage change between these two colums.  I tried this:
    I added a Adjacent column group for Period column and I grouped by the calculated column "ColumnDiff".  Add the following expression.
    =(SUM(Fields!Calificacion.Value)- Previous(SUM(Fields!Calificacion.Value),"ColumnDiff"))/Previous(SUM(Fields!Calificacion.Value),"ColumnDiff")
    After that I get: 
    I'm getting the sum of the two columns instead.
    Any clue about what I'm doing wrong? Please help me, I've been looking for the answer but any solution works for me.
    Luis Carlos

    Hi Luis,
    According to your description, you have a report with different dynamic columns. Now what you want is show your user percentage growth in your matrix report after your user select two of those columns (I think you may use parameter to achieve your “checkbox”
    function). Is my understanding correct?
    In Reporting Service, we can’t calculate dynamic columns with our build-in arrogation functions. So we need to add custom code into our report, and call those functions which defined in custom code in our expression. We have tested your scenario in our local
    environment. Here are steps and screenshots for your reference.
    Go to your Report Properties, add the custom code below into your report:
    Dim Shared Num1 As Double
    Dim shared Num2 As Double
    Public Function GetCalification(Calification as Double,Type as String,Type2 as String) 
    If Type = Type2 Then
       Num1=Calification
    Else
       Num2=Calification
    End If 
    Return Calification 
    End Function
    Public Function GetPec()
    Return (Num2-Num1)/Num1
    End function
    Create a matrix. Put PilarName into Row field, put Period into Column field. In Data field, put the expression below into the textbox:
    =Code.GetCalification(Fields!Calification.Value,Fields!Period.Value,Parameters!Period.Value(0))
    In our sample report, we created a parameter (named Period) for selecting two columns. You can replace “Parameters!Period.Value(0)” with your own parameter.
    Add an outside column at right (%Growth), put the expression below into the textbox:
    =Code.GetPec()
    Save and preview. The matrix and result looks like below:
    Reference:
    Custom Code and Assembly References in Expressions in Report Designer (SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

Maybe you are looking for