From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

running a user-defined function in mathscript node

Hello,

Iam trying to incorporate matlab user-defined image processing function FRST in labview as I could not find a vi assosiated for it. I obtained this function from the internet and I implemented it in matlab and it works well.Now i'm trying to add it to labview using the mathscript node.This function requires an input image as a parameter 

Also FRST function calls another user -defined function and a mex file, will labview automatically search and run these functions???I have added the search path to this folder in the mathscript window and to the node and it still shows errors telling unexpected char '.'  for grad.x and grad.y in:

 

grad = gradient(im);% grad is user defined function and is within FRST script
Mag = sqrt(grad.x.^2 + grad.y.^2);

 

Anyone can tell me how to solve this issue

0 Kudos
Message 1 of 12
(9,508 Views)

Hi,

 

You should replace the script with

 

[fx, fy] = grandient(im);

Mag = sqrt(fx.^2 + fy.^2);

 

Check syntax of MathScript gradient in the following page.

http://zone.ni.com/reference/en-XX/help/373123C-01/lvtextmath/msfunc_gradient/

Message 2 of 12
(9,497 Views)

Thank you i got that problem solved but now there is a problem with the mex file as i cannot seem to incorporate into the node.......and also i have been facing problems as the program uses in-buit functions of matlab such as imfilt,fspecial etc and this is not accepted by the node.....so is it possible to send images from labview to matlab environment without using the mathscript node so that all these functions are recognised and image processing is implemented in matlab and the results are transferred back to labview???

0 Kudos
Message 3 of 12
(9,492 Views)

Hi,

 

If you have Matlab installed, you can use the Matlab Script Node. You can find it in Mathematics>>Scripts & Formulas>>Script Nodes palette.

 

Check more information in the following page.

http://zone.ni.com/reference/en-XX/help/371361K-01/gmath/matlab_script_node/

Message 4 of 12
(9,489 Views)

Thank you....i wrote my code onto the script node but then during execution my user-defined function was not recognized so at the beginning i used cd to specify the path to the folder ...it solved that problem but now i'm getting an error telling that my output variable is not defined???? here's my code

 

cd C:\Users\Shastry\Documents\MATLAB\FRST   % Path to my folder for user-defined function fastradial.m
b=imcomplement(a);                                             % a is a 2D-real array to the node(input image)
G=fspecial('gaussian',[13 13],1.4);
c=double(b);
S=fastradial(c,50,3,.05);
figure(1);
subplot(221);
imshow(a);
subplot(222);
imshow(b);
subplot(223);
imshow(S);
[M N]=size(S)
for i=1:M
for j=1:N
if(S(i,j))>=1
d(i,j)=255;
else
d(i,j)=0;
end
end
end
subplot(224)
imshow(d);

 

%d (binary image) is not defined for some reason and i have taken it as output from the node

0 Kudos
Message 5 of 12
(9,481 Views)

I forgot to mention that when matlab command window opens I seem to get this problem


SIT: Added paths for Simulation Interface Toolkit Version 5.0
Warning: Calling MEX-file 'E:\SimulationInterfaceToolkit\5.0\Lib\NISITServer.dll'.
MEX-files with .dll extensions will not execute in a future version of MATLAB. 
Error using NISITServer
Unable to open library SIT_InterfaceWindow.dll.

Error in matlabrc (line 215)
NISITServer;

 

Could this prove to be a problem? I'm truly confused....could you please help me

 

0 Kudos
Message 6 of 12
(9,478 Views)

I have never used the Matlab Script Node. Does the same code work well in Matlab environment?

 

You can try to define d before the for loop.

0 Kudos
Message 7 of 12
(9,459 Views)

yes it does work in matlab ....although i have to read an image from a file rather than present the input image through labview........i'll check with the output and let you know

0 Kudos
Message 8 of 12
(9,454 Views)

Just search the ni.com and find the following help regarding NISITServer.

 

Communicating with the SIT Server

Configuring the SIT Server

 

I am not sure whether you could remove the SIT configure code from matlabrc.m if you do not use it.

0 Kudos
Message 9 of 12
(9,450 Views)

Hello,

I finally got the vi to run....i guess the problem was because i had imported the code from my working directory into the node and made changes ..... i guess it wasn't registered or something so i typed the main program and ran it ....it works well....do you have any suggestions on how i can reduce the execution time as it takes about 200msec for execution of the matlab  pogram alone and i want the result in real-time so i need to reduce it by 50%

0 Kudos
Message 10 of 12
(9,432 Views)