简体   繁体   English

如何加载.mat文件并在Octave或Matlab中设置变量名?

[英]How to load a .mat file and set the variable name in Octave or Matlab?

Apparently Matlab load loads the data from a .mat file into the variable that it was saved. 显然,Matlab的load加载从数据.mat文件到变量,它被保存。

How can you load a single matrix from a .mat or binary file into an arbitrary variable? 如何将.mat或二进制文件中的单个矩阵加载到任意变量中?

Load it in to a struct and pop it out to your variable. 将其加载到结构中并将其弹出到您的变量。

saved_name = 'varname_it_was_saved_as';
s = load('some_file.mat', saved_name);
my_new_variable = s.(saved_name);

I always use the struct forms of save and load for production code. 我总是使用save和load的结构形式来生成代码。 It's cleaner because it doesn't dynamically fiddle with your workspace. 它更干净,因为它不会动态地摆弄你的工作区。

See help load for details. 有关详细信息,请参阅help load

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM