I have a structure with fields ID,Coor,Misc,Conn. ID and Misc are doubles, however, Coor is a 1×3 vector and Conn is a 1xn vector (where n can theoretically be from 0 to inf).
Point(x).ID = [x]
Point(x).Coordinate = [xPos yPos zPos]
Point(x).Misc = [randomDouble]
Point(x).Conn = [someVectorOfNumbers]
I would like to have this mapped on a cell array, without using a FOR loop.
An example of the output:
'ID xPos yPos zPos Misc Conn'
1 0 0 0 0 '0 1 2'
2 1 1 1 1 ''
...
x x x x x '2'
Notice that Point.Conn, its vector of numbers gets converted into a string.
The issues that I am having is breaking up Point.Coordinate into its three elements, and converting Point.Conn into a string.
I feel like this can be done using struct2Cell and then changing the nesting level. I’m just not exactly sure how to do that.
First make some example data:
Now inspect it:
Now use
arrayfun()to sweep through the elements of structure arrayPoint. We define a generic functionxto operate on each element ofPoint, formatting the row like you described:Now inspect the output:
Couldn’t tell from your question, but if you want all the numeric fields as an array inside a single cell, that is an easy tweak to do. Good luck!