I would like to load multiple files in a loop. Is it possible to merge strings as follows:
subjects=cell(19,1);
subjects{1}='s1';
subjects{2}='s2';
subjects{3}='s3';
subjects{4}='s4';
...
file_end='_stimulus1.mat';
I would need to merge subjects{i} and file_end to get:
data = load('s1_stimulus1.mat')
...
Thanks already in advance!
-Maria

 採用された回答

Star Strider
Star Strider 2014 年 8 月 6 日
編集済み: Star Strider 2014 年 8 月 6 日

0 投票

One way:
for k1 = 1:size(subjects,2)
fname = [subjects{k1} file_end]
load(fname)
end

2 件のコメント

Maria
Maria 2014 年 8 月 6 日
Many thanks for the answer!
-Maria
Star Strider
Star Strider 2014 年 8 月 6 日
My pleasure!

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

その他の回答 (2 件)

Iain
Iain 2014 年 8 月 6 日

1 投票

e.g.
string1 = 'blah';
string2 = 'bla-de-blah';
string3 = [string1 string2];
You'd need something like:
data = load([subjects{i} file_end]);

1 件のコメント

chocho
chocho 2017 年 3 月 13 日
if we have 'bla de blah' and want: bla-de-blah?

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

Mahesh
Mahesh 2014 年 8 月 6 日

0 投票

I think you also can do as follows
for i = 1:size(subjects,2
mergestring = strcat(cell2str(subjects{i}),file_end)
end
I think this will help you too as an alternative codes as suggested above

カテゴリ

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

タグ

質問済み:

2014 年 8 月 6 日

コメント済み:

2017 年 3 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by