LabVIEW MathScript RT Module

Showing results for 
Search instead for 
Did you mean: 

Accessing MATLAB 'ndgrid' file

Go to Solution

Accessing MATLAB 'ndgrid' file

Hi, I am an beginner user of LabView's MathScript Module, I have two problems when integrating my MATLAB code into LabView, for image reconstruction process:


1. For example I have an array which contains both positive and negative numbers: a = -5:5 (This will give me an array 'a' of -5 -4 -3 -2 -1 0 1 2 3 4 5)

    If I would like to get rid of the negative values in this array, in MATLAB, I will do: a(a<0)=0 (This will give me an array 'a' of 0 0 0 0 0 0 1 2 3 4 5)


    However, in LabView Mathscript, this command gives me the following error:


Error -90026 occurred at Error in function = at line 44:  The indexes for a matrix indexing operation must be real, positive integers.
LabVIEW:  The indexes for a matrix indexing operation must be real, positive integers.


Is there any way to avoid this error message?



2.  In my program, I tried to call a built-in MATLAB function called 'ndgrid.m'

     LabView dont know this function initially, which shows me the following error message:


Error -90031 occurred at Unknown symbol on line 18: ndgrid




    I then copy the 'ndgrid.m' file from the MATLAB folder and copy it under the LabView working directory, but the following errors come up:


Error -90162 occurred at Line 38, Column 12: unexpected char: '{'

    C:\Documents and Settings\ms350\Desktop\MIT_KENT\ndgrid.m

LabVIEW:  A recognition error occurred while generating a stream of tokens.




It seems like MathScript is complaining about the "{"   "}" symbols. Is there any way to overcome these errors?







0 Kudos
Message 1 of 5 (6,020 Views)
0 Kudos
Accepted by topic author hykwei
‎08-27-2015 06:09 PM

Re: Accessing MATLAB 'ndgrid' file

[ Edited ]

Hi hykwei,


The VI snippet below addresses both issues:


1.  The code:

a = -5:5;a(a<0) = 0;

 should definitely work.  If you have a warning glyph (), however, you'll get the error you mentioned.  This has been reported to R&D (#223605) for investigation.  If you look at the snippet, you can use for loops and if statements to create the same result.  Refer to this post for more information on resolving warning glyphs (MathScript Nugget #6: Warning Glyphs).


2.  ndgrid doesn't appear to be a default command for MathScript (MathScript RT Module Supported Functions).  I'm also pretty sure that the module doesn't allow curly brackets in its syntax, so that could be the reason for the error you see.


What you can do in the meantime is use the meshgrid2d function to assign values to 2 variables (if you use context help you can get the documentation or type help meshgrid2d in the MathScript window).  I added some sample code in the VI snippet below to show how to use the function.  Also, the custom function instructions may be a good help:




Message Edited by Smootastic on 05-04-2010 12:32 PM
Message 2 of 5 (6,015 Views)

Re: Accessing MATLAB 'ndgrid' file

Dear Smootastic


Thanks alot for your help!


the a(a<0)=0; function still does not work, and there is no warning glyph next to the code as you suggested. But I replaced the code with for and if command, its now working fine.


In my other code, there is another MATLAB function called 'griddata', I used it to create a 3D matrix using interpolation of another matrixs.


There is no 'griddata' function inside LabView, but seems like there is a replacement LabView function called  'intrp2d_uneven'.


The following error occurs when I run the program:


Error -90070 occurred at Error in function intrp2d_uneven at line 51:  The lengths of the two input vectors are not compatible.
LabVIEW:  The lengths of the two input vectors are not compatible.


I am using the intrp2d_uneven function in the following format:


ZS = intrp2d_uneven(X, Y, Z, XS, YS, method)    % as shown on the NI website


The dimension of each parameter are:


X = 1x15, Y=1x15, Z=15x15, XS=200x200, YS=200x200, method = 'cubic'


The dimensions are also the same when run in MATLAB. So I actually dont know where the problem came from?





Is the LabView 'plotf_surf' function equivalent to the MATLAB's 'surf' function?






Message 3 of 5 (5,993 Views)

Re: Accessing MATLAB 'ndgrid' file

Hello hykwei,


to your question



Is the LabView 'plotf_surf' function equivalent to the MATLAB's 'surf' function?



If you are looking for an equivalent for "surf", you would want to use "surface" in MathScript.

plotf_surf plots a function of two variables as a 3D surface

surface  plots a 3D surface based off x,y,z matrix that you specified.



Andy Chang
National Instruments
LabVIEW Control Design and Simulation
Message 4 of 5 (5,986 Views)

回复: Re: Accessing MATLAB 'ndgrid' file



The MathScript function intrp2d_even requires that Z must be of the same size as X and Y. For your inputs, you could try


[XX, YY] = meshgrid2d(X, Y);ZS = intrp2d_uneven(XX, YY, Z, XS, YS, method);


Message 5 of 5 (5,965 Views)