将结构体的字段加载到变量中 (MATLAB)
我的硬盘上存储了一个结构。我需要将其字段之一加载到局部变量中。一个简单的负载会得到“
% '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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 MATLAB 7 或更高版本,则可以使用
-struct
标志保存结构体:如果您以这种方式保存结构体,则可以加载结构体的特定字段,而无需加载所有结构体结构体的字段:
If you are using MATLAB 7 or higher, you can save your struct using the
-struct
flag: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:
您无法从 MAT 文件加载变量的一部分。您需要:
或
查看 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:
or
See MATLAB help: http://www.mathworks.co.uk/help/techdoc/ref/load.html