poster
2019-12-14, 20:46
给定一个具有多个未知字段的函数的结构,如何获得每个字段的名称?
例如:
s = struct; s.hello = 'world'; s.foo = 12; s.bar = [ 1 2 3 ]; 我想要s(1),s(2)和s(3)的名称。在这种情况下,我会得到“ hello”,“ foo”和“ bar”。
回答:
您正在寻找FIELDNAMES (http://www.mathworks.com/help/techdoc/ref/fieldnames.html)
fieldnames(s) fn = 'hello' 'foo' 'bar' 请注意, fn是一个单元格数组,因此您将获得'foo'作为fn{2}
更多&回答... (https://stackoverflow.com/questions/5419518)
例如:
s = struct; s.hello = 'world'; s.foo = 12; s.bar = [ 1 2 3 ]; 我想要s(1),s(2)和s(3)的名称。在这种情况下,我会得到“ hello”,“ foo”和“ bar”。
回答:
您正在寻找FIELDNAMES (http://www.mathworks.com/help/techdoc/ref/fieldnames.html)
fieldnames(s) fn = 'hello' 'foo' 'bar' 请注意, fn是一个单元格数组,因此您将获得'foo'作为fn{2}
更多&回答... (https://stackoverflow.com/questions/5419518)