问题
If I already have a .mat file with the variables x and y, is there a way to use the save command to add another variable z to the .mat file without having to explicitly state the variables x and y in the save command?
回答1:
If you look at the save() function documentation, there is a form of the save command that might help:
save(filename, ..., '-append')
The help for this form says:
save(filename, ..., '-append')adds new variables to an existing file. You can specify the '-append' option with additional inputs such as variables, '-struct' , format, or version.
回答2:
From the manual page:
save(filename) save(filename, variables) save(filename, '-struct', structName, fieldNames) save(filename, ..., '-append') save(filename, ..., format) save(filename, ..., version) save filename ......
save(filename, ..., '-append')adds new variables to an existing file. You can specify the'-append'option with additional inputs such as variables,'-struct', format, or version.
来源:https://stackoverflow.com/questions/8509315/how-to-append-a-variable-to-a-mat-file