如何在 matlab 中将每次运行的输出值保存在同一文件中
我在每次运行时得到两个不同的(数字和字符)输出值,我想将这些值保存在文件中,以便在另一个进程中使用它们。我将它们保存在数组结构中,然后将它们保存在(mat 文件)中,如下所示:
Sim(i).No Sim(i).Nam
save('Sim', 'Sim")
我想在每次运行时将这些值保存在同一个文件中......问题是在下一次运行中我只得到上次运行的值。
I get two different (numeric and character )output values at each run, I want to save these value in a file in order to use them in another process. I saved them in a struct of array then I saved them in (mat file) as follow:
Sim(i).No
Sim(i).Nam
save('Sim', 'Sim")
I want to saved these value at each run in the same file ... the problem is in the next run I get just the values of the last run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 SAVE< 的
'-append'
选项/a> 将数据添加到已保存的文件中。但是,您需要小心地使用不同的名称保存每次运行,否则您将覆盖保存文件。因此,你可以这样做:
You can use the
'-append'
option of SAVE to add data to a saved file. However, you need to be careful to save each run with a different name, otherwise you'll just be overwriting the save file.Thus, you could do something like this:
您正在尝试增量地将结构数组保存到磁盘,因此每次都需要加载、追加和重新保存数组(对于非常大的数据,不建议这样做)
:上面假设您在代码前面定义了 No 和 Nam。
如果您在循环中运行它,更好的方法是将 Sim 保留在内存中并在循环结束时保存整个结构体数组。
You are trying to save-to-disk a struct array incrementally, so you need to load, appended, and re-save the array each time (something that is not recommended for very large data):
The above assumes you have No and Nam defined earlier in the code.
If you were running this in a loop, a better approach would be to just keep Sim in memory and save the entire struct array at the end of the loop.