Iterate through custom bus datatype fields CMex
14 次查看(过去 30 天)
显示 更早的评论
Hi,
I have some custom bus datatypes defined in my base MATLAB workspace. I now need to dynamically iterate through their fields to dynamically allocate enough memory, dynamically create structs with their structure and values, etc. pp.
My first intention was to search for a built-in function, but I couldnt find one. Then I saw the ssGetDataTypeName function, but I could not even get a value by calling mexCallMATLAB with ".Elements(1).DataType" appended to the result of the ssGetDataTypeName function. Instead an error gets thrown claiming MATLAb doesn't know a variable or function named like that.
Does anybody has a hint for me? Thanks in advance!
P.S.: Of course, all actions I try to perform from within the Simulink block succeed in the plain MATLAB environment doing it manually. There is no error like an undefined variable or a bad defined bus or something. It's working, just not dynamically.
1 个评论
Rik van der Struijk
2020-11-6
编辑:Rik van der Struijk
2020-11-6
Hi Rob,
I am trying to achieve the same as you. Have you ever found an elegant solution?
回答(1 个)
James Tursa
2014-6-10
If you have a struct in your mex routine (call it st) and need to get at the .Elements(1).DataType field element, you will need to do it in steps.
mxArray *Elements, *DataType; // arbitrary variable names
Elements = mxGetField(st,0,"Elements"); // first get the Elements field
Datatype = mxGetField(Elements,0,"DataType"); // then get the DataType subfield
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Event Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!