help with load command: how to use data set without knowing name prior to loading

Hi,
When I load a .mat file, a data set get loaded into my session. If I do a 'whos' I can see the name of the data set, or sets.
My question is, is it possible to assign or use this data set by name, without knowing it prior to loading it and checking it with 'whos'.
I hope that makes sense, I am grateful for any help.
Thank you, Scott

 采纳的回答

file = 'f.mat';
S = load(file);
fn = fieldnames(S); %assuming one variable
data = S.(fn{1})
Load the file into a structure and extract the variable from it using dynamic fieldnames.
Note: I would recommend trying to get a consistent variable name.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

产品

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by