Importing matlab data in a loop using keywords from a cell
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have two cell arrays:
a1={K01 mainEEG.mat,K02 mainEEG.mat,K03 mainEEG.mat,....,K10 mainEEG.mat}
a2={K01 file1.mat',K02 file2.mat,K05 file3.mat}
Now i want to import files present in a2 from a1 using initial string as keyword i.e K01, K02 and K05. Can someone please help me with this?
2 个评论
Walter Roberson
2016-9-4
Why do I get the sinking feeling that the output you want from this is a variable named "file1" that matches all of the filename parts of the entries whose string starts with 'K01', and a variable named "file2" that matches all of the filename parts of the entries whose string starts with 'K02', and so on?
采纳的回答
Thorsten
2016-9-5
编辑:Thorsten
2016-9-5
a1 = {'K01 mainEEG.mat','K02 mainEEG.mat','K03 mainEEG.mat', 'K04 mainEEG.mat', 'K05 mainEEG.mat', 'K06 mainEEG.mat'}
a2 = {'K01 file1.mat', 'K02 file2.mat' , 'K05 file3.mat'}
prefix1 = cellfun(@(c) c(1:3), a1, 'UniformOutput', false)
prefix2 = cellfun(@(c) c(1:3), a2, 'UniformOutput', false)
files_I_want_to_import = a1(ismember(prefix1, prefix2))
0 个评论
更多回答(1 个)
dpb
2016-9-4
编辑:dpb
2016-9-5
>> c1=char(a1);c2=char(a2);
>> list=a1(ismember(c1(:,1:3),c2(:,1:3),'rows'))
list =
'K01 mainEEG.mat' 'K02 mainEEG.mat'
>>
It's a little easier to subscript the char arrays since can't dereference a substring of an array of cellstr in a single operation (or, at least, I don't know of any syntax to do so)...
NB: I just deleted the ellipses from you defining line rather than fill in the other elements so K05 was not in a1 in the above demo. Also, it's not clear precisely whether it's a1 or a2 you're actually wanting, use the appropriate one, of course...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!