如何在表中创建可变数量的列标题?

时间:2017-05-09 13:28:45

标签: matlab variable-names matlab-table

Here is a pic of a possible table.

我最想要的是标题

@IBAction func email(_ sender: Any) {

    if !MFMailComposeViewController.canSendMail() {
        let warnung = UIAlertController(title: "Email konnte nicht gesendet werden", message: "Dein Gerät unterstützt leider keine Email-Funktion.", preferredStyle: .alert)
        let action1 = UIAlertAction(title: "OK", style: .default, handler: nil)
        warnung.addAction(action1)
        self.present(warnung, animated: true, completion: nil)
        return

        } else {

            mail.mailComposeDelegate = self
            mail.setToRecipients(["team@example.com"])
            mail.setSubject("Message to you")
            mail.setMessageBody("Hello,\n", isHTML: false)

            present(mail, animated: true, completion: nil)
        }
    }
}

func mailComposeController(_ controller: MFMailComposeViewController,
                                   didFinishWithResult result: MFMailComposeResult, error: NSError?) {
            mail.dismiss(animated: true, completion: nil)
            print("Yes!")
}

被称为

"Var1", ..., "VarN"

我已经尝试过使用"Student no.", "Name", "Assignment 1", ..., "Assignment N-2" 字段,但似乎无法使其正常工作(我可以正确地命名为“Var1”和“Var2”,但不知道会有多少分配让我无法为其余人命名。)

有没有优雅的方法来做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以先获取表格中的变量名称数量,然后使用sprintfstrsplit为作业生成一组字符串:

nVars = numel(T.Properties.VariableNames);
varNames = strsplit(sprintf('Assignment_%d ', 1:(nVars-2)));
T.Properties.VariableNames = [{'Student_no' 'Name'} varNames(1:(end-1))];

请注意,字符串中不能包含空格或句点(即它们的格式与normal variable naming的格式相同)。