Converting Matlab function to mex with user defined class object
이전 댓글 표시
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
Adam
2014년 11월 3일
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
2014년 11월 3일
To convert an object to a struct:
s = struct(obj);
Adam
2014년 11월 4일
Oh yeah...that was too obvious to remember!
Amit
2014년 11월 11일
Guillaume
2014년 11월 11일
Answer to this question, in the answers below
채택된 답변
추가 답변 (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
Dalia Sobhy
2017년 12월 14일
편집: Dalia Sobhy
2017년 12월 14일
Hello
It is not working
카테고리
도움말 센터 및 File Exchange에서 Algorithm Design Basics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!