Conversion of argument 2 from "real_T [2]" to "const int []" not possible;

4 次查看(过去 30 天)
Hi I am trying to call my function in coder.ceval method. The function declaration of my code in header file is :
STATE_SPACE_EQN_DLL_EXPORT extern void State_Space_Eqn(const double a_data[],
const int a_size[2], const double b_data[], const int b_size[2], const double
c_data[], const int c_size[2], const double d_data[], const int d_size[2],
double x_data[], int x_size[2], const double u_data[], const int u_size[2],
double out_data[], int out_size[2]);
And I am calling it by using coder.ceval method as follows:
function output = State_Space_Eqn_X(A,B,C,D,X,U)
% Running in generated code, call library function.
coder.cinclude('State_Space_Eqn.h');
output = coder.nullcopy(U);
a = size(A);
b = size(B);
c = size(C);
d = size(D);
x = size(X);
u = size(U);
out = size(output);
coder.ceval('State_Space_Eqn', coder.rref(A),a,coder.rref(B),b,coder.rref(C),c,coder.rref(D),d,coder.rref(X),x,coder.rref(U),u,coder.wref(output),out);
end
When I call this function in Matlab function block on Simulink, I am getting this error:
Conversion of argument 2 from "real_T [2]" to "const int []" not possible;
The types referenced are not linked; the conversion requires a reinterpret_cast operator or a type conversion in C or function format.
Can someone please help me in this code?

采纳的回答

Geoff Hayes
Geoff Hayes 2020-5-9
Bhushan - I don't use Simulink so don't know for sure if this will work but if the error message is telling you that it can't convert from a real (double) to an integer, then maybe you have to do the conversion yourself. Remember that the class type of the array returned by size is still a double so try to do the conversion there
function output = State_Space_Eqn_X(A,B,C,D,X,U)
% Running in generated code, call library function.
coder.cinclude('State_Space_Eqn.h');
output = coder.nullcopy(U);
a = int32(size(A));
b = int32(size(B));
c = int32(size(C));
d = int32(size(D));
x = int32(size(X));
u = int32(size(U));
out = int32(size(output));
coder.ceval('State_Space_Eqn', coder.rref(A),a,coder.rref(B),b,coder.rref(C),c,coder.rref(D),d,coder.rref(X),x,coder.rref(U),u,coder.wref(output),out);
end
I'm assuming that an int32 is equivalent in C to an int.
  2 个评论
Bhushan Ravindra Attarde
Yes. This is working perfectly fine for me. I tried using int64 but was showing same error. Can you please explain why it was not working with int64?
Thank you for your valuable time.
Geoff Hayes
Geoff Hayes 2020-5-11
Bhushan - in C/C++, an integer, int, is typically 32 bits so that is why you need to convert your size dimensions from the (probably) 64-bit doubles to a 32-bit integer via int32. When you use int64, this will convert the doubles to 64-bit integers which is not the expected/required 32 bits as given in the function signature.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by