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

 採用された回答

Sean de Wolski
Sean de Wolski 2013 年 4 月 8 日
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 ExchangeMATLAB についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by