LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

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
0 Kudos
Message 1 of 14
(13,096 Views)
Chris,

The issue most likely has to do with the path.  The default path for LabVIEW MathScript is your My Documents\LabVIEW Data directory.  Try placing your .m file into that folder or add a line at the beginning of your MathScript node to set the path to the location where your .m file resides.  To set the path, type
path('c:\work');
and specify the location of your folder.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
Message 2 of 14
(13,082 Views)

Grant

thank you for the suggestion, i will attempt that but i have  more questions based on this.

 

1.  is there a way to define a different working directory so i dont have to be path specific in all my files?

2.  If the sub that is being called by the routine in the node calls additional subs, would the path have to be defined in every sub, or dose math script remember the path and not revert to default for calls from the subs?  ( I hope that isn't to confusing 🙂  )

 

3.  which method is more efficient in mathscript.  to use function calls outside of the node (multiple sub routines)  or to move those subs up into the node, so that the node is one long script with outside function calls?

 

Thanks again for the help

chris

0 Kudos
Message 3 of 14
(13,079 Views)
Chris,

Those are great questions.  Let me address them in the order you asked:

1) To change the defaults for the path and working directory, launch the MathScript Window by going to Tools>>MathScript Window.  When it loads, go to File>>MathScript Preferences.  Here you can adjust the path and working directory.  By changing the directories in here, you don't need to include a path command in your MathScript node.

2) The MathScript path is a global setting.  Changing it in one node will affect all nodes and the MathScript Window.  You may wish to use the addpath command to simply add a directory to the path instead of changing the entire path.  When calling subroutines, you do not need to worry about setting the path appropriately in those files.  However, if another node has changed the path and removed a directory, then your files may not work as expected.  But if nothing else is modifying the path, your subroutines will receive the same path.

3) It is more efficient to break your code into several subroutines than to have all your code in one node.  The MathScript internals operate more efficiently on smaller blocks of code at a time.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
Message 4 of 14
(13,070 Views)
Grant thank you again for your timely response and great answers.  I actually moved all my sub routines up into one large script in the node yesterday just for testing purposes and i get some vague cant compile errors, including one that said send the script to N!.  unfortunatly the script contains IP I cant release.  is there any guidance on what to look for with this type of error, maybe that we are calling a function thats doen't exist or something specific that i can look for? is that just a general catch all error?
0 Kudos
Message 5 of 14
(13,065 Views)
Chris,

It is a catch-all error of sorts.  It is thrown when there is some unexpected syntax in the script.  The syntax is valid (hence a parser error is not thrown), but there is a bug in the code generation.  We know of a few issues that currently do not work.  You can look for the following:
  • Using foreign characters in a string (e.g. a = 'étoile'; )
  • Using the return keyword
  • In a function producing multiple outputs, assigning one output to a matrix element or submatrix (e.g. [A(2:5, 3:6) D] = eig(rand(4)); )
  • Deeply nested structures (8 or more levels of if, switch, for, or while statements)
If these suggestions do not help, you can try a binary search approach where you keep halving the code to compile and only continue the search in the half that still contains the error.  This should allow you to find the offending line.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments

Message Edited by GrantM on 04-14-2006 08:47 AM

Message 6 of 14
(13,054 Views)

Thank you for the thorough answer, the code was originally written in Japan, and there were a lot of japanese comments in it.  I thought I removed all but I may have missed a couple, seems like that is the obvious start.  There are also quite a few if loops, this being a filtering and normalization routine.  I would never have thought of checking how deep the nests are...

 

and i like the code halving approach that sounds like quite a time saver.

 

Thanks again...I will let you know how it turns out

Chris

0 Kudos
Message 7 of 14
(13,032 Views)
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
0 Kudos
Message 8 of 14
(12,979 Views)
Hi Chris,

Are you still seeing the same error as you originally reported: Pre_Process_Function_Pulse being an unknown symbol?  If so, it is likely that the unsupported syntax is in that file.  LabVIEW MathScript tries to compile any m-script files, if needed, when they are called.  If there is an error in the function and it is unable to compile, you will see the unknown symbol error.  In order to help track this down, try the following.  Launch the MathScript Window.  Load the Pre_Process_Function_Pulse.m file into the script editor.  Click the Save & Compile button.  This will save the file and then attempt to compile it.  Any compiler errors will be reported in the Output Window.  Currently, this is the only mechanism by which function compiler errors are reported.

Also, the use of cell arrays and structures is not supported in LabVIEW 8.0 MathScript.  This might be the cause as well, but try the save and compile option and see if anything shows up.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 9 of 14
(12,974 Views)
Grant,
I took your advice and checked all of my .m files in the mathscript tool.  I found some issues with most of them around for and if statements not working with parenthesis, as well as not being able to use the & sign.  now all of the sub routines that my main subroutine (the one called in the mathscript node) except one compile.  I have copied the .m file that is giving me the contact NI error below.  Hopefully you can tell me what I am missing in this script?
 
Once more thanks so much for the time patience and help with this problem!
Chris
 
 
 
 
function [st00,en00,Z]= noisy_region_remove_puls(test_data,Z0,RegionA ,EVENT1);
Z=Z0;
k1=1;
k2=1;
for i=2:length(Z),
   if Z(i) == 0 and (Z(i) - Z(i-1) < 0)
      st00(k1)=i;
      k1=k1+1;
 elseif Z(i-1) == 0 and (Z(i) - Z(i-1) > 0)
      en00(k2) =i-1;
      k2=k2+1;
   end
end
if k1<2
 st00(1)=1;  
end
if k2<2
 en00(1) = length(Z);  
end
if (en00(1) < st00(1))
   sttmp=[ 1 st00];
   st00 = sttmp; 
end
if (length(en00) < length(st00))
   en00(length(en00)+1) = length(Z); 
end
0 Kudos
Message 10 of 14
(12,968 Views)