Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我本质上想要的是标题
"Var1", ..., "VarN"
被称为
"Student no.", "Name", "Assignment 1", ..., "Assignment N-2"
我试过搞乱这个T.properties.Variablenames领域,但似乎无法让它发挥作用(我可以正确命名“Var1”和“Var2”,但不知道会有多少作业让我无法命名其余的他们)。
T.properties.Variablenames
有什么优雅的方法可以做到这一点吗?
sprintf您可以首先获取表中变量名称的数量,然后使用and为赋值生成一组字符串strsplit:
sprintf
strsplit
nVars = numel(T.Properties.VariableNames); varNames = strsplit(sprintf('Assignment_%d ', 1:(nVars-2))); T.Properties.VariableNames = [{'Student_no' 'Name'} varNames(1:(end-1))];
请注意,字符串中不能有空格或句点(即它们遵循与普通变量命名相同的格式)。