Create a struct inside a cell array
3 次查看(过去 30 天)
显示 更早的评论
I'm using struct2xml from FileExhange and it's quite picky on the format of the structure to export. Basically I loose information when exporting data arrays (they are converted to strings). Example;
x = 1:3;
s.child.Text = x;
xml = struct2xml(s)
xml =
<?xml version="1.0" encoding="utf-8"?>
1 2 3
As you can see, the array of doubles has been converted into a string which makes it cumbersome for me to read the data back. I would like to have a format of;
<?xml version="1.0" encoding="utf-8"?>
1
2
3
but here's my pickle. In order for that to happen, I have to have a cell array of child-objects with a struct('Text', Value) in each.
s.child.Text = num2cell(x);
won't work, as struct2xml ultimately expects a struct (with field Text) but only gets a cell.
s.child = struct('Text', num2cell(x));
won't work, as that generates three separate structs. Multiple structs must be in cells.
cellfun(@struct, 'Text', num2cell(x));
won't accept the field name 'Text' unfortunately.
Any brilliant ideas?
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!