set variable to data that is loaded

Hello all,
Hopefully a very easy question. I am loading a file named matfile.mat that's value is double. I want to set my variable as the data that is loading, but when I put "x=load(matfile)" it returns "x=matfile: [1001x14 double]". I know I can type in x.matfile to access the data manually, but I run into issues when figuring out how to do this for my function. Any help is greatly appreciated!

 採用された回答

Daniel Shub
Daniel Shub 2011 年 10 月 25 日

1 投票

x = load('matfile.mat');
temp = fieldnames(x);
x = x.(temp{1});

3 件のコメント

Kevin
Kevin 2011 年 10 月 25 日
Fieldnames!!! Just what I needed thanks so much.
Kevin
Kevin 2011 年 10 月 25 日
Ah, also the {} are needed too.
Daniel Shub
Daniel Shub 2011 年 10 月 25 日
The {} make/index CELL arrays. They are like [], but have some advantages (and disadvantages).

サインインしてコメントする。

その他の回答 (1 件)

Grzegorz Knor
Grzegorz Knor 2011 年 10 月 25 日

1 投票

If you are sure that you load only one matrix:
fName = fieldnames(x);
eval(['x = x.' fName{1} ';'])
Another possibility:
x = cell2mat(struct2cell(x))

2 件のコメント

Daniel Shub
Daniel Shub 2011 年 10 月 25 日
You can eliminate the eval with dynamic field names.
Kevin
Kevin 2011 年 10 月 25 日
Thanks too Grzegorz!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

質問済み:

2011 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by