Indexing over all values in nested struct

妖精的绣舞 提交于 2019-12-02 09:51:45

Use the combination of two functions below:

cell2mat(struct2cell(mystruct.level1))

There's a structfun to do just that. It will return another struct, with the same names. So for your case:

con_struct = structfun (@(x) [x.a x.b], mystruct, "UniformOutput", false);

Now, con_struct will have the same fields as mystruct, but instead of a struct, each of them is an array with the values you wanted. You can feed each of arrays again to whatever function you want

structfun (@foo, con_struct)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!