将结构体的字段加载到变量中 (MATLAB)

发布于 2024-12-02 05:40:16 字数 356 浏览 1 评论 0原文

我的硬盘上存储了一个结构。我需要将其字段之一加载到局部变量中。一个简单的负载会得到“

% 'PRICES' is the stored struct.  1st fieldname is '.Raw'.  
% Only '.Raw' needs to be loaded

var = load( fullfile(path, 'PRICES.Mat') ) % Wrong as var becomes a struct containing a struct.
% DESIRED value: var = PRICES.Raw ;

是否可以一步完成此操作?”我当然可以覆盖 var 并完成此操作,但是有直接的方法吗?谢谢。

I have a struct stored onto my harddrive. I need to load one of its Field into a local variable. A simple load gets the

% 'PRICES' is the stored struct.  1st fieldname is '.Raw'.  
% Only '.Raw' needs to be loaded

var = load( fullfile(path, 'PRICES.Mat') ) % Wrong as var becomes a struct containing a struct.
% DESIRED value: var = PRICES.Raw ;

Is it possible to do this in 1 step? I can ofcourse overwrite var and accomplish this, but is there a direct way of doing it? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黒涩兲箜 2024-12-09 05:40:16

如果您使用的是 MATLAB 7 或更高版本,则可以使用 -struct 标志保存结构体:

save(fullfile(path, 'PRICES.Mat'),'-struct','PRICES');

如果您以这种方式保存结构体,则可以加载结构体的特定字段,而无需加载所有结构体结构体的字段:

load(fullfile(path, 'PRICES.Mat'),'Raw');
disp(Raw);

If you are using MATLAB 7 or higher, you can save your struct using the -struct flag:

save(fullfile(path, 'PRICES.Mat'),'-struct','PRICES');

If you save your struct this way, then you can load a specific field of the struct without loading all of the struct's fields:

load(fullfile(path, 'PRICES.Mat'),'Raw');
disp(Raw);
半岛未凉 2024-12-09 05:40:16

您无法从 MAT 文件加载变量的一部分。您需要:

var = load( fullfile(path, 'PRICES.Mat'), 'PRICES' );
var = var.PRICES.Raw;

load( fullfile(path, 'PRICES.Mat'), 'PRICES');
var = PRICES.Raw;

查看 MATLAB 帮助:http://www.mathworks。 co.uk/help/techdoc/ref/load.html

You can't load part of a variable from a MAT-file. You want either:

var = load( fullfile(path, 'PRICES.Mat'), 'PRICES' );
var = var.PRICES.Raw;

or

load( fullfile(path, 'PRICES.Mat'), 'PRICES');
var = PRICES.Raw;

See MATLAB help: http://www.mathworks.co.uk/help/techdoc/ref/load.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文