Importing matlab data in a loop using keywords from a cell
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 4 Set 2016
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?
Sowmya MR
il 4 Set 2016
Risposta accettata
Più risposte (1)
>> 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...
Categorie
Scopri di più su Cell Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!