Clear Filters
Clear Filters

Function return types in Matlab Coder

13 views (last 30 days)
Kara657
Kara657 on 14 Jun 2023
Commented: Kara657 on 15 Jun 2023
Hello, I am investigating the Matlab Coder functionality. I have 2 quick questions let's say I have the following function in Matlab:
function int_point = my_cross(line1,line2)
int_point = cross(line1,line2);
end
The corresponding C++ function generated by the coder is the following:
void my_cross(const double line1[3], const double line2[3], double int_point[3])
{
int_point[0] = line1[1] * line2[2] - line2[1] * line1[2];
int_point[1] = line2[0] * line1[2] - line1[0] * line2[2];
int_point[2] = line1[0] * line2[1] - line2[0] * line1[1];
}
Question 1) Is there a way to have the c++ function having return type double instead of returning as parameter?
Question 2) In the generated c++ function where my_cross is called the parameters are passed by pointer but I want to pass by value. Can I change this behaviour?
Thanks.

Answers (1)

Mukund Sankaran
Mukund Sankaran on 14 Jun 2023
Hello,
Another similar question was posed a while ago, and the answer there contains some more specifics as well: https://www.mathworks.com/matlabcentral/answers/781348-matlab-coder-generated-a-c-function-which-has-void-output-even-though-the-matlab-function-has-doubl
Hope this helps!

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!