Created nested structures using the Matlab API
2 views (last 30 days)
Show older comments
I'm currently working on a program that writes output data into an ASCII file, and then we later execute a Matlab command in batch mode to turn the ASCII files into .mat files. This takes a lot of time, and I have read about using the Matlab API libraries to create the .mat files for you. I've been somewhat successful with this as I've been able to create a .mat file full of scalar values, but have not been able to figure out nested structures. I know I can create a single structure with fieldnames, but then those fieldnames are expected to be a matrix or scalar. I would like to create a structure within that structure. For example, a structure called part, with fieldnames of gaussian and uniform, each of those with fieldnames of x and y, and each of those with fieldnames of stdDev and mean. I would greatly appreciate any help as I'm really stuck right now. Thanks!
4 Comments
James Tursa
on 25 Sep 2013
Edited: James Tursa
on 26 Sep 2013
OK. I presume your data is in the form of native C/C++ memory (i.e., arrays or dynamically allocated memory using malloc and friends). Is this true? Would it be possible to change your code to use MATLAB Memory Manager memory instead (i.e., allocated using API functions like mxMalloc, mxCreateDoubleMatrix, etc)? That would make the mat file writing a lot easier.
Also, this statement you made is not true: "... those fieldnames are expected to be a matrix or scalar ..." The field elements can be any mxArray variable, including struct arrays or cell arrays or whatever. They are not restricted to be a numeric matrix or scalar.
The basic procedure is to simply link to the appropriate API libraries (I simply build as an Engine application for stuff like this even though I don't actually open up an Engine since this process will get the necessary libraries linked automatically) and then call the mx and mat functions you need.
Answers (0)
See Also
Categories
Find more on Deploy to C++ Applications Using mwArray API (C++03) 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!