Iterate through custom bus datatype fields CMex
14 views (last 30 days)
Show older comments
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 Comment
Rik van der Struijk
on 6 Nov 2020
Edited: Rik van der Struijk
on 6 Nov 2020
Hi Rob,
I am trying to achieve the same as you. Have you ever found an elegant solution?
Answers (1)
James Tursa
on 10 Jun 2014
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
See Also
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!