Pattern matching problem

6 visualizzazioni (ultimi 30 giorni)
B_Richardson
B_Richardson il 11 Lug 2011
Hello Community,
I have some video files named using the following pattern:
SHC_LL_S1_0008_V5.5983338494.avi
RHA_RL_S3_0008_v1.59806163.avi
SLR_LL_S1_0008_v1.59806163.avi
I also have some .mat data that corresponds to each video file:
2009-10-15 09-23-54_SHC_RL_S1_0008FinalData
2009-10-15 09-59-31_SLR_RL_S3_0008FinalData
2009-10-15 09-57-11_SLR_RL_S1_0008FinalData
I need to figure out how to load the data files automatically depending on the video selected? I have some experience using the strfind(itemselected,pattern1) function but so far I havent been able to come up with the logic to slove this issue.
Maybe I could store the name of the currently playing video to a variable then try to match that? The key identifiers in the names of both files are:
SHC_LL_S1 SHC_RL_S1

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 11 Lug 2011
Something like this. BTW, I have to modify your video file name to find a match.
VideoFiles={'SHC_LL_S1_0008_V5.5983338494.avi';
'RHA_RL_S3_0008_v1.59806163.avi';
'SLR_LL_S1_0008_v1.59806163.avi'};
DataFiles={'2009-10-15 09-23-54_SHC_LL_S1_0008FinalData';
'2009-10-15 09-59-31_SLR_RL_S3_0008FinalData';
'2009-10-15 09-57-11_SLR_LL_S1_0008FinalData'};
for k=1:length(VideoFiles)
Pattern=VideoFiles{k}(1:9);
Index=strfind(DataFiles,Pattern);
Index=cellfun(@isempty,Index);
FoundDataFile=DataFiles(~Index)
end
  11 Commenti
Jan
Jan il 11 Lug 2011
@Jiang: cellfun('isempty', C) is much faster than cellfun(@isempty, C).
Fangjun Jiang
Fangjun Jiang il 11 Lug 2011
Thanks, Jan. You or somebody else must have reminded me before. I need to stick it into my mind.

Accedi per commentare.

Più risposte (1)

Vairis Caune
Vairis Caune il 30 Apr 2012
I would suggest an alternative:
VideoFiles={'SHC_LL_S1_0008_V5.5983338494.avi';
'RHA_RL_S3_0008_v1.59806163.avi';
'SLR_LL_S1_0008_v1.59806163.avi'};
for k=1:length(VideoFiles)
Pattern=VideoFiles{k}(1:14); %take whatever you want
matfiles=dir(fullfile('C:\placeindisc\folder',['*' Pattern '*']))
if(length(matfiles)~=1)
warning('multiple matches or no matches');
else
load(matfiles(1).name)
end
end
If you can have multiple data files per video, then add
for iter=1:length(matfiles)
load(matfiles(iter).name)
end

Community Treasure Hunt

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

Start Hunting!

Translated by