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 Exchange에서 Characters 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