Labview Matlb Call Function

22 visualizaciones (últimos 30 días)
Robert Schemmel
Robert Schemmel el 3 de Jul. de 2024
Comentada: Umar el 7 de Jul. de 2024
What VALUE should be in the Return Type for a Labview DBL in a Labview Matlab Call Function
  4 comentarios
Umar
Umar el 5 de Jul. de 2024
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.
Robert Schemmel
Robert Schemmel el 5 de Jul. de 2024
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).

Iniciar sesión para comentar.

Respuestas (7)

Umar
Umar el 4 de Jul. de 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 comentarios
Umar
Umar el 4 de Jul. de 2024
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.
Robert Schemmel
Robert Schemmel el 4 de Jul. de 2024
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

Iniciar sesión para comentar.


Umar
Umar el 5 de Jul. de 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 comentario
Robert Schemmel
Robert Schemmel el 5 de Jul. de 2024
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 ?

Iniciar sesión para comentar.


Umar
Umar el 5 de Jul. de 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 comentarios
Robert Schemmel
Robert Schemmel el 7 de Jul. de 2024
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
Umar
Umar el 7 de Jul. de 2024
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

Iniciar sesión para comentar.


Umar
Umar el 6 de Jul. de 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 el 7 de Jul. de 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 el 7 de Jul. de 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 comentarios
Umar
Umar el 7 de Jul. de 2024
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.
Robert Schemmel
Robert Schemmel el 7 de Jul. de 2024
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)

Iniciar sesión para comentar.


Robert Schemmel
Robert Schemmel el 7 de Jul. de 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 comentario
Umar
Umar el 7 de Jul. de 2024

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

Iniciar sesión para comentar.

Categorías

Más información sobre LabVIEW en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by