Labview Matlb Call Function

What VALUE should be in the Return Type for a Labview DBL in a Labview Matlab Call Function

4 Comments

It seems to me that you are asking about what specific code number needs to be inserted in a Labview MATLAB Call Function in order for the return type to be interpreted as DBL.
The specific code is unlikely to be 42.
Unfortunately I do not know the answer to the question, and I am having difficulty finding relevant documentation. What documentation I can find says https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/call-matlab-function.html
return type specifies the data type of return value. You must wire a constant or control matching the data type of the top level MATLAB function return type to return type. For example, if the MATLAB function returns an array of doubles, you must wire an array of doubles constant or control to return type. If the MATLAB function returns multiple values, wire a cluster with elements the correspond to the MATLAB function return values. The name and data types and order of the cluster elements must match the MATLAB function return values. For example, if the MATLAB function returns a numeric, a Boolean array, and a string, you must wire return type to a cluster containing controls or constants of numeric, Boolean array, and string data types in that order. Cluster element names must be unique and not empty. If the MATLAB function does not return any value, leave return type unwired.
Personally, I would interpret this as indicating that the value you wire in is not important; that LabView examines the type of what you wire in. But I could be wrong.
Perhaps it would help if I explain why I am asking the question.
For almost a month I have been trying to learn the syntax (labview equivilent) of the Labview Matlab Call Function because I bought Matlab in January of 2019 and used it with Udemy online courses for a couple of years and then stopped using it because I was busy with other things. About a year and a half ago I got a job (I'm an Electronics Engineering Tech with a 3-yr DeVry BSEET degree) working at a company that uses Labview.So I bought Labview Base and started using it at home with online courses. One day I stumblled across the Matlab Call Function while
looking for a function and thought it was a cool idea. I spent three weeks trying to get it to work with no success.
I started using clusters and arrays and then decided to simplify it by only using DBLs. I got the simplest possible
Matlab .m script working on Matlab and couldn't get it to work because I didn't know what to plug into the Return Type
DBL Numeric Control. Everything else looked correct. So I got so frustrated trying to run it over and over with no
success so I started plugging random numbers into the Return Type DBL Numeric Control and all it did was return
the same value in the Return Value Numeric Indicator. I tried 0 and got 0 back, then 1, got 1 back , 2, 3 etc, After
five or six random tries I thought 'to hell with it !' land typed in '100' and immediately got the correct calculation result
for the simple area equation. I tried other radius values and the answer was always correct . So being a technician
I knew that it didn't mean 100 was the CORRECT value unless it didn't work with the orginial values (0,,1,2,3 etc)
It had to be repeatable. So I changed the 100 in the Return Type control to '1' and it still worked returning the correct
area calculation. So did 2, 3, 4 and finally '0'. So now where does that leave me ? I can't say '100' is the correct value
because NOW it works with ANY value but I swear it did NOT start working until I plugged in '100'. So you can
imagine why I am curious about WHAT value should be in the Return Type regardless of Ni saying any value is fine
as long as the data type matches the Return Value type. I know I'm not crazy but I just can't buy that there is no
significance to the '100' value that made it start working. And there you have it..(sorry to be so vrbose)
Hi Robert,
Thank you for sharing your experience with trying to learn the syntax of the Labview Matlab Call Function. It sounds like you have put in a lot of effort and encountered some frustration along the way. Based on your detailed explanation, it seems that you were able to achieve the correct calculation result by plugging in the value '100' into the Return Type DBL Numeric Control. While it may seem unusual, I understand your curiosity about why this particular value made it start working.
In any case, I appreciate your dedication to learning and problem-solving, and I hope that you will find a satisfactory resolution to your question.
Thanks for the reply. I may never find out why the value '100' made it start working but made two other programs to test the Matlab Call Function. One with eight input args that adds up your bills and returns a total expenses and one with one input arg 't' and two output args 's' (displacement) and 'v' (velocity) that calculates the displacement in feet and velocity in feet per second of a ship at sea. (the equation doesn't make sense to me because t is in minutes and if you enter 60 the velocity is -510 feet per second but I copied it from a Udemy online course and get the same result in Matlab so my Labview program works but I didn't know how to handle two output args so I cascaded two Matlab Call Functions , each returning one output arg. I was going to try six output args the same way but didn't have time but I know it will work. The multiple cascaded Call Functions execute so fast that all results appear to be returned simultaneously but in actual fact there's a millisecond range propagation delay that is undetectable with the human eye.
I should use the Time Stamp function to quantify it (later).

Sign in to comment.

Answers (7)

Umar
Umar on 4 Jul 2024
Hi Robert,
To answer your question,the Return Type should be set to 'DBL' to ensure that the correct data type is handled and returned from the Matlab function to Labview.
Hope this answers your question.

5 Comments

DBL is NOT a VALUE. It is a DATA TYPE. The question was what VALUE should be entered into the DBL Numeric Control connected to the Call Function RETURN TYPE TERMINAL.
Hi Robert,
Thanks for clarification. So, one possible solution is to use a specific numeric value that represents a double-precision floating-point number, which is the data type typically associated with DBL. For example, you can use the double function to create a double-precision array.
% Create a double-precision array
dbl_value = double(42.0);
By assigning the double value to the DBL Numeric Control in Labview, you can ensure that the correct data type is passed to the Matlab function and returned accurately.
Don't need an array. A DBL Numeric Control is sufficient. So to clarify, ANY VALUE greater than 42.0 would qualify as a DBL ? Can you explain WHY 42 and not 41 or 43 ? Robert
Hi Robert,
To answer your questions, please see my answers below.
ANY VALUE greater than 42.0 would qualify as a DBL ? Can you explain WHY 42 and not 41 or 43 ?
The choice of 42.0 as a reference point for a DBL Numeric Control is arbitrary and not a strict rule. other values above it would also be suitable.
What makes 42 a DBL ? 42 decimal = 00101010 bit-7 128 ....0 bit-6 64.....0 bit-5 32.....1 bit-4 16.....0 bit-3 8.....1 bit-2 4.....0 bit-1 2.....1 bit-0 1.....0
DBL (Double Precision Floating Point Byte 0 = 00101010 (bytes 1 -7 are all zeroes) So WHY 42 (or greater) and NOT 41 ? (or any other number) ?
00101010 binary 32+8+2 = 42

Sign in to comment.

Umar
Umar on 5 Jul 2024

Dear Robert,

When working with Matlab functions that have multiple output arguments, it is essential to understand how to handle and extract these outputs efficiently. In your case, where you have a function returning two output arguments 's' (displacement) and 'v' (velocity), you can easily capture and utilize these values in your code. Just in case, I am providing an example of how you can handle multiple output arguments in Matlab functions:

function [s, v] = calculateShipValues(t)

    % Your calculation logic here
    s = % Calculate displacement based on 't'
    v = % Calculate velocity based on 't'

end

% Call the function and retrieve the outputs

t = 60; % Assuming 't' is 60 minutes

[s, v] = calculateShipValues(t);

disp(['Displacement (s): ', num2str(s), ' feet']);

disp(['Velocity (v): ', num2str(v), ' feet per second']);

the calculateShipValues function takes 't' as an input and calculates both displacement 's' and velocity 'v'. By calling the function with a specific value of 't', you can retrieve and display the calculated values accordingly.

Regarding cascading multiple Matlab Call Functions to handle multiple output arguments, your approach seems effective. By chaining these functions, you can process the outputs sequentially and achieve the desired results. However, as you mentioned, using a timestamp function to quantify the propagation delay is a good practice to ensure accurate timing measurements.

If you plan to expand to handling more output arguments in the future, cascading the functions as you did with two outputs is a viable approach. Just ensure that the order of execution and data flow between these functions are correctly managed to avoid any issues.

Keep exploring and testing different scenarios to enhance your understanding and optimize your code further.

1 Comment

If you're using num2str then does that mean the Return Type is STRING and NOT DBL ? Also, there's only ONE Return Type input and ONE Return Value . Both have to be the same Type. So HOW am I going to get TWO output args if I only have ONE Output Value indicator and WHAT TYPE is it ?

Sign in to comment.

Umar
Umar on 5 Jul 2024
Dear Robert,
I don’t know if you like the answer but in Matlab, when using num2str, the return type is indeed a string (STRING) and not a double (DBL). If you need to obtain multiple output arguments with only one output value indicator, you can achieve this by using square brackets to encapsulate the multiple outputs. This way, you can assign each output to a different variable. The output type will depend on the specific function being used and the data it returns. By structuring your output variables correctly, you can handle multiple return values effectively in Matlab.

11 Comments

Thanks. Will try it on Monday when I get home.
No problem, Robert. Sounds good and have a safe trip back home.
Attached is a screenshot of the vi and the Matlab.m file. I don't have Matlab on this laptop so all I can do right now is create the Labview vi because I installed Labview on this laptop.
Let me know if it looks ok.
Thanks,
Robert
Attached are the vi, the .m file and the screenshot in a zip file.
Let me know if it looks correct.
Thanks,
Robert
Hi Robert,
Please do me a favor before I take a peek. Send me screenshots of results both vi and .m file that you sent me.
You are probably already aware of executing vi file by clicking the run button in the LabVIEW toolbar. Also, utilizing matlab, type the filename calculateShipValues and press Enter. I am sure that you already know how to run the script by clicking on the "Run" button in the Matlab Editor after opening the .m file which will execute the script and display the output in the command window.

However, I took the liberty to execute your file calculateShipValues.m and found no issues with it. Please see attached.

I will wait for screen shot of test results of your vi file.

I'm just curious. If the Return value is two strings of fractional numbers, does that constitute a string array ?
Can I use the Fract/Exp String to Number to convert the string floating point numbers to Numeric doubles or would there be a problem because there are two floating point numbers in the string ? Would I first have to convert the string array to a numeric array and if so how would I do that if I wanted the numbers to be Numric indicators on the front panel ?
(see attached screenshots of proposed block diagram to do this) (I suspect this won't work because technically the return value is a string array)
Robert
Hi Robert,
To convert two strings of fractional numbers into a string array in Labview, you can use the "Build Array" function to create a string array with the two fractional number strings. Regarding converting the string floating-point numbers to Numeric doubles, you can indeed use the Fract/Exp String to Number function in Labview. This function can handle converting the strings to numeric values, even if there are two floating-point numbers in the string. To display these converted numeric values as Numeric indicators on the front panel, you can simply wire the output of the conversion function to the Numeric indicator on the front panel. This will allow you to visualize the numeric values in real-time.
After thinking about it , it occurred to me that the Return Value must be a Delimited string with a space (' ') as the delimiter so I came up with this diagram as a possible approach. What do you think ?
Robert
I'm still out of town using my cheap Dell computer that I bought for email and recently install Labview on,
I can't install Matlab on it because Mathworks requires the first installation to be deactivated from Matlab before you can install it on a different system so all I can do is create Labview programs. I won't know if any of them work until I get home tonight so I'm trying to lay the groundwork from this location and test it when I get home.
Robert
Hi Robert,
After reviewing your labview vi and matlab calculateShipValues.m, they don’t match. If you trying to integrate the calculateShipValues.m MATLAB function into LabVIEW using a MATLAB script node, you need to follow these detailed steps:
Step 1: Create a MATLAB Script Node in LabVIEW
Open LabVIEW and create a new VI (Virtual Instrument). Drag and drop a MATLAB script node from the Functions palette onto the block diagram.
Step 2: Implement the MATLAB Function in LabVIEW
Copy the MATLAB function calculateShipValues.m code into the MATLAB script node in LabVIEW.Modify the MATLAB code to adhere to LabVIEW syntax and structure. Ensure that the input and output variables are correctly defined.
Step 3: Define Inputs and Outputs
Define the input t in LabVIEW. This input will be passed to the MATLAB script node.Define outputs s and v in LabVIEW to receive the calculated displacement and velocity values from the MATLAB script node.
Step 4: Call the MATLAB Function
Wire the input t to the MATLAB script node.Wire the outputs s and v from the MATLAB script node to the desired indicators or controls in LabVIEW for display.
Step 5: Run the LabVIEW VI
Run the LabVIEW VI to execute the MATLAB script node with the calculateShipValues.m function.Verify that the displacement s and velocity v values are calculated and displayed correctly in LabVIEW.
Example LabVIEW Code Snippet
Here is an example LabVIEW code snippet demonstrating the integration of the calculateShipValues.m MATLAB function:
% Add inputs and outputs t = 5; % Sample time value
% MATLAB script node [s, v] = calculateShipValues(t);
% Display results disp(['Displacement (s): ', num2str(s), ' feet']); disp(['Velocity (v): ', num2str(v), ' feet per second']);
For more information on utilizing matlab code into labview, please refer to
https://forums.ni.com/t5/LabVIEW/How-to-call-MATLAB-function-from-LabVIEW-s-MATLAB-Script/td-p/3178832
https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/script-node.html

Sign in to comment.

Umar
Umar on 6 Jul 2024

Hi Robert,

What are you trying to accomplish exactly in labview, please provide details, so I can guide you to achieve your goal. Are you having trouble executing program in labview?

Robert Schemmel
Robert Schemmel on 7 Jul 2024
Attached are the Matlab .m script file and the Labview .vi file.
The script file runs correctly in Matlab without any modifications.
However the Labview program initially threw an error that it was expecting a cluster because there were multiple values.
I changed it to what it is in the attached file. At this point all I can say is that for some reason it isn't working. My cascaded Matlab
Call Fuction returns the correct calculated values but I can't get this approach to work and I don't know why. You tested the Matlab script and got the same results I did (no errors). Can you see if you can figure out what is wrong with my vi ?
Robert
Robert Schemmel
Robert Schemmel on 7 Jul 2024
This is the vi I started with before I changed it to the one I just sent you. This approach assumes the Return Type is a delimited string with a space delimiting the 's' and the 'v' results. As you can see , Labview expects a cluster so I changed it to a cluster as
shown in the last vi I sent you. Neither approach works, despite the Matlab script working flawlessly in Matlab.
Robert

3 Comments

If you get the vi working can you please send it in zip file. If you don't have Winzip and you send it as a screenshot can you please make the labels visible so I can tell what functions you used ?
Thanks,
Robert
Hi Robert,
I don’t have access to labview but I did provide my comments few seconds ago. Please review them and share your feedback.
Labview Mathscript Nodes were Deprecated for Windows systems in 2023.
Please see the following NI page:
NI recommends 'MIGRATING' to the Matlab Call Function.
"Drag and drop a MATLAB script node from the Functions palette onto the block diagram."
Since the whole point of this thread is about using the Matlab Call Function in Labview, it appears that we may have reached an impasse because there is no Matlab Script node in the Functions pallete (starting in 2024)

Sign in to comment.

Robert Schemmel
Robert Schemmel on 7 Jul 2024
"Step 1: Create a MATLAB Script Node in LabVIEW
( MATLAB Script Nodes are not in LabVIEW 2024 (my version)
Open LabVIEW and create a new VI (Virtual Instrument).
Drag and drop a MATLAB script node from the Functions palette onto the block diagram.
( MATLAB Script Nodes are not in LabVIEW 2024 (my version)
Step 2: Implement the MATLAB Function in LabVIEW
Copy the MATLAB function calculateShipValues.m code into the MATLAB script node in LabVIEW.
Modify the MATLAB code to adhere to LabVIEW syntax and structure. Ensure that the input and output variables are correctly defined.
(I'm sorry but this isn't much help since the problem since the beginning has been that I don't know how to do that)
Step 3: Define Inputs and Outputs (same problem)
Define the input t in LabVIEW. This input will be passed to the MATLAB script node.Define outputs s and v in LabVIEW to receive the calculated displacement and velocity values from the MATLAB script node.
(already done)
Step 4: Call the MATLAB Function
Wire the input t
Open LabVIEW and create a new VI (Virtual Instrument).
Drag and drop a MATLAB script node from the Functions palette onto the block diagram.
(again, no script nodes in labview 2024)
Step 2: Implement the MATLAB Function in LabVIEW
Copy the MATLAB function calculateShipValues.m code into the MATLAB script node in LabVIEW.Modify the MATLAB code to adhere to LabVIEW syntax and structure. Ensure that the input and output variables are correctly defined.
Step 3: Define Inputs and Outputs
(again, don't know how to do that)
Define the input t in LabVIEW. This input will be passed to the MATLAB script node.Define outputs s and v in LabVIEW to receive the calculated displacement and velocity values from the MATLAB script node.
Step 4: Call the MATLAB Function
Wire the input t"
(since this problem is about integrating Matlab AND Labview, I don't see how it can be resolve with only the advice of a Matlab
expert and not a Labview expert. I appreciate all the time you have spent trying to help but , to quote FireSign Theater :
"You can't get there from here....")

1 Comment

Hi Robert,

Good catch, however there is alternative approach to resolve this issue without using without using a MATLAB script node if you are up for it, it can be achieved by converting the MATLAB function into a MATLAB DLL (Dynamic Link Library) and then calling this DLL from LabVIEW. This approach allows for seamless integration between the two environments.To convert the calculateShipValues.m MATLAB function into a MATLAB DLL, follow these detailed steps:

First, ensure that the MATLAB function calculateShipValues.m is well-defined and returns the required outputs. The function should have the following structure:

function [s,v] = calculateShipValues(t) s = 5*t.^2 + 90*t - 80; v = 90 - 10*t; disp(['Displacement (s): ', num2str(s), ' feet']); disp(['Velocity (v): ', num2str(v), ' feet per second']); return end

Use MATLAB's mcc command to compile the MATLAB function into a DLL. This command generates a standalone executable or shared library from the MATLAB code. Here is an example of how you can compile the function:

mcc -W lib:calculateShipValues -T link:lib calculateShipValues.m

In LabVIEW, you can use the Call Library Function Node to call functions from DLLs. Follow these steps to call the MATLAB DLL from LabVIEW:

Open LabVIEW and create a new VI.Drag a Call Library Function Node onto the block diagram.Configure the node to call the functions exported by the MATLAB DLL.Pass the input parameters to the function and receive the output values.

By following these steps, you can effectively integrate the MATLAB function calculateShipValues into LabVIEW without using a MATLAB script node. This method ensures efficient communication between MATLAB and LabVIEW, allowing you to leverage the strengths of both environments seamlessly.

veni, vidi, vici

Sign in to comment.

Products

Release

R2019b

Asked:

on 3 Jul 2024

Commented:

on 7 Jul 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!