How can i convert my user class object into a mex file?

6 visualizaciones (últimos 30 días)
Daniele Nanni
Daniele Nanni el 28 de Oct. de 2021
Comentada: Walter Roberson el 28 de Oct. de 2021
I have read https://www.mathworks.com/help/matlab/matlab_external/mex-functions-for-class-methods-1.html that I can convert functions into mex file and call these functions in the object's methods.
But ones I try to convert the functions using the coder app, I receive the following error: Entry point cannot be inside a class folder.
What I am doing wrong?
My function, defined in the method class is a sort of:
function out = step(Obj)
modulated_sym = zeros(1,Obj.FEC*Obj.signal_config.n_sym);
for nn = 1:Obj.FEC
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Turbo Encoder %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[coded_bits_to_punc] = step(Obj.signal_config.hTEnc,Obj.tx_bits((length(Obj.tx_bits)/Obj.FEC)*(nn-1)+1:nn*(length(Obj.tx_bits)/Obj.FEC)).');
coded_bits_to_punc = coded_bits_to_punc(1:end-16);
coded_bits_to_punc = [coded_bits_to_punc(1:3:end-2); coded_bits_to_punc(2:3:end-1); coded_bits_to_punc(3:3:end)];
Obj.len_to_punc = length(coded_bits_to_punc);
coded_bits = coded_bits_to_punc(Obj.signal_config.punc_pattern);
.....
end
Is the " Obj." that is not working for the coder?

Respuestas (1)

Walter Roberson
Walter Roberson el 28 de Oct. de 2021
You cannot use MATLAB Coder to convert a class method into a mex file. You can only convert functions outside of classes.
This implies that the function to convert could only use the public interfaces to the object properties to get data or change the object.
  2 comentarios
Daniele Nanni
Daniele Nanni el 28 de Oct. de 2021
Thank you for you answer!
I understand. I have the problem that, in my project, I have to use different objects. And the speed of the entire program is very slow. I thought that converting some of the methods in mex file could be a good compromise.
Do you know any technique that is possible to apply to speed up the execution of the program?
Thanks a lot!
Walter Roberson
Walter Roberson el 28 de Oct. de 2021
struct() are faster than objects. Carefully arranged numeric arrays are faster than struct() .
If you use a class folder, then the class folder can contain mex files. However, you cannot selectively convert class methods written in m-code into mex; furthermore, the mex API makes objects pretty much opaque, if I recall correctly.

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by