Converting Matlab function to mex with user defined class object
Ältere Kommentare anzeigen
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
Adam
am 3 Nov. 2014
I think you can convert the class to a struct to retain its properties, but lose its functions which are obviously not transferable to mex.
I can't remember off-hand how to do this though so you could probably search for that as fast as I could!
Guillaume
am 3 Nov. 2014
To convert an object to a struct:
s = struct(obj);
Adam
am 4 Nov. 2014
Oh yeah...that was too obvious to remember!
Amit
am 11 Nov. 2014
Guillaume
am 11 Nov. 2014
Answer to this question, in the answers below
Akzeptierte Antwort
Weitere Antworten (1)
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
Dalia Sobhy
am 14 Dez. 2017
Bearbeitet: Dalia Sobhy
am 14 Dez. 2017
Hello
It is not working
Kategorien
Mehr zu Algorithm Design Basics finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!