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

2 views (last 30 days)
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

Accepted Answer

Sean de Wolski
Sean de Wolski on 8 Apr 2013
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.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!