LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call MATLAB function from LabVIEW's 'MATLAB Script'?

I have a MATLAB m-file as follows:

 

testfcn.m

function [A,B] = testfcn(C)

A = log10(C);
B = C.^2;

 

How can I call this function testFcn from a MATLAB Script in LabVIEW? See pleaseHelpMeMakeItWork.vi for an illustration of the problem. The attached vi x`attempts to run

 

Attempted Script Node Code

codeShot.png

 

It does not work. I get

errorCode_1050.png

 

So, ehrm, what the heck here? For context here is the code location on my machine -

 

dirShot.png

 

This testfcn() works just fine in MATLAB, see example_working.m. But like, how to use it in LabVIEW?

 

Attachments

  • I attached the VI pleaseHelpMeMakeItWork.vi which was mentioned above.
  • For the example MATLAB file testfcn.m it is posted as testfcn.txt because forums.ni.com refused to accept a *.m file... 🙂

 Important Context

The answer 'just cut and paste your sub-routine into the script, no function calls needed'  doesn't count either... 🙂

justinmreina@gmail.com
Download All
0 Kudos
Message 1 of 5
(10,518 Views)

An anwser may be here -

 

    MathScript Nugget #10: How To Call User-Defined Functions

 

But from what I see here this requires MATLAB RT (Real-Time), so this does not apply as a generic solution?

justinmreina@gmail.com
0 Kudos
Message 2 of 5
(10,476 Views)
Another solution may be found somewhere within here:
http://www.ni.com/white-paper/7006/en/
Message 3 of 5
(10,464 Views)

Keep in mind, you're essentially saying "See!  My m-file exists right here!  It exists!  How can LabVIEW not see it!?"  What steps have you taken to help LabVIEW see where it is saved on your machine?

0 Kudos
Message 4 of 5
(10,070 Views)

Hi
Some kind of late answer.
You need to add the path of the function in the matlab script.
Add this on top of your matlab script:
path(path, 'function's path');

0 Kudos
Message 5 of 5
(6,552 Views)