How can I merge two strings?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Star Strider
2014-8-6
编辑:Star Strider
2014-8-6
One way:
for k1 = 1:size(subjects,2)
fname = [subjects{k1} file_end]
load(fname)
end
更多回答(2 个)
Iain
2014-8-6
e.g.
string1 = 'blah';
string2 = 'bla-de-blah';
string3 = [string1 string2];
You'd need something like:
data = load([subjects{i} file_end]);
Mahesh
2014-8-6
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!