Converting Matlab function to mex with user defined class object
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Amit
am 3 Nov. 2014
Kommentiert: Matt J
am 12 Sep. 2023
I need to create a mex file of a function. One of the arguments of the function is the matlab user defined class object. When I try to convert the function to mex, it gives me an error that the function input does not have valid type and user defined class is not supported by coder.type. Is there any solution to this?
5 Kommentare
Akzeptierte Antwort
Ryan Livingston
am 4 Nov. 2014
Bearbeitet: Ryan Livingston
am 17 Dez. 2017
Edit: As of MATLAB R2017a value objects can be inputs and outputs from MEX files.
In earlier releases, MATLAB Coder does not support the input or output arguments of the MEX function being MATLAB objects. One other option you have is to pass the values to the MEX function needed to construct the object and construct the object inside the function being passed to codegen. So rather than:
function y = foo(myObj)
<code>
you could use:
function y = foo(arg1,arg2,arg3,)
myObj = MyClass(arg1,arg2,arg3);
<code>
Then you can use the object as before in the code and still generate MEX from the function.
Using the struct approach, you could pass in the struct and then re-create the object from the struct inside of the function.
1 Kommentar
Matt J
am 12 Sep. 2023
Edit: As of MATLAB R2017a value objects can be inputs and outputs from MEX files.
Are there any relevant documentation links with examples that you could provide?
Weitere Antworten (1)
Guillaume
am 11 Nov. 2014
Bearbeitet: Guillaume
am 11 Nov. 2014
To convert a structure back to an object you can do the following function
function object = propfromstruct(object, s)
for fieldname = fieldnames(s)'
try
o.(fieldname) = s.(fieldname);
catch ex
warning('could not copy field %s due to error %s', fieldname, ex.message);
end
end
end
1 Kommentar
Siehe auch
Kategorien
Mehr zu Fixed-Point Conversion finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!