Load a file by using a string in which the filename is stored

I use these commands to create string with all names of the files that have a mat extension.
files = dir('*mat'); filenames = {files.name};
Now I want to load one of these files by just using a number
load(filenames(1)) or load filenames(1) or load('filenames(1)')
But none of these commands work. Any ideas?

 採用された回答

Açmae
Açmae 2013 年 3 月 1 日
編集済み: Açmae 2013 年 3 月 1 日

2 投票

Hi Rudy -
'filename(1)' is a 1x1 cell in your case. In order to access the content of the cell, you would use curly brackets.
>> load(filename{1})
Cheers, Açmae

1 件のコメント

ANKUR KUMAR
ANKUR KUMAR 2017 年 10 月 8 日
How can I copy a file whose name is stored in variable?

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

その他の回答 (1 件)

Rudy
Rudy 2013 年 3 月 3 日

0 投票

Thanks, that fixed it!!

カテゴリ

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

質問済み:

2013 年 3 月 1 日

コメント済み:

2017 年 10 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by