Matlab字段名称索引 [英] Matlab Fieldnames indexing
本文介绍了Matlab字段名称索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个包含多个表的单元格数组,我正在尝试访问该表的第一列名称.
So I have a cell array with multiple tables and I am trying to access the first column name of the table.
c={'table1', 'table2', 'table3'}
以下两行都给我错误:
fieldnames(c{1})(1)
fieldnames(c{1}){1}
Error: ()-indexing must appear last in an index expression.
但是,如果我执行以下操作,它将起作用:
But if I do following, it works:
fn=fieldnames(c{1})
fn{1}
有一种方法可以用一行代码来做到这一点,有人可以解释该错误吗?
Is there a way to do this with one line of code and can someone please explain the error?
推荐答案
通常,可以使用函数调用(仅返回输入的虚拟函数)解决此类问题,也可以仅用显式调用
Generally such problems can be solved using a function call (either a dummy function that just returns the input) or you could just replace the fn{} with an explicit call to subsref
:
subsref(fieldnames(c{1}),substruct('{}',{1}));
Regarding your question about why the error happens - maybe this link could help.
这篇关于Matlab字段名称索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文