help with load command: how to use data set without knowing name prior to loading
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!