Matlab:加载.mat文件,为什么是结构?我可以将存储的vars加载到内存中吗? [英] Matlab: loading a .mat file, why is it a struct? can I just have the stored vars loaded into memory?
问题描述
相关代码:
function result = loadStructFromFile(fileName, environmentName)
result = load(fileName, environmentName);
bigMatrix = loadStructFromFile('values.mat','bigMatrix');
但是当我在工作区中查看时,它显示'bigMatrix'为1x1结构.但是,当我单击该结构时,它就是实际数据(在本例中为998x294矩阵).
But when I look in the workspace, it shows 'bigMatrix' as a 1x1 struct. When I click on the struct, however, it is the actual data (in this case a a 998x294 matrix).
推荐答案
As the documentation of LOAD indicates, if you call it with an output argument, the result is returned in a struct. If you do not call it with an output argument, the variables are created in the local workspace with the name as which they were saved.
对于函数loadStructFromFile
,如果保存的变量名称可以具有不同的名称(我假设为environmentName
),则可以通过写操作返回变量
For your function loadStructFromFile
, if the saved variable name can have different names (I assume environmentName
), you can return the variable by writing
function result = loadStructFromFile(fileName, environmentName)
tmp = load(fileName, environmentName);
result = tmp.(environmentName);
这篇关于Matlab:加载.mat文件,为什么是结构?我可以将存储的vars加载到内存中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!