Search code examples
matlabdir

process a list with specific name and extension in matlab


I'm trying to process a list of files that start with the same string, but only the .mat files. In my folder I have log files with names such as:

CADS3P5Ph1_LKS_20141210_EVAL_103443_001.avi                   
CADS3P5Ph1_LKS_20141210_EVAL_103443_001_MeasData.mat 
CADS3P5Ph1_LKS_20141210_EVAL_103443_002.avi                  
CADS3P5Ph1_LKS_20141210_EVAL_103443_002_MeasData.mat  
CADS3P5Ph1_LKS_20141210_EVAL_103443_003.avi             
CADS3P5Ph1_LKS_20141210_EVAL_103443_003_MeasData.mat  
CADS3P5Ph1_LKS_20141210_EVAL_104236_001.avi           
CADS3P5Ph1_LKS_20141210_EVAL_104236_001_MeasData.mat  

I only need to process the files that have the same timestamp (e.g. 103443_xxx) I made a variable looking with a wildcard

filename = CADS3P5Ph1_LKS_20141210_EVAL_103443_001_MeasData.mat
general_name = filename(1:end - 17); 
general_name = strcat(general_name,'*','');

So when I do dir(general_name), it finds all the files that start with "CADS3P5Ph1_LKS_20141210_EVAL_103443", How do I only get the .mat files, and not the .avi files I tried

dir(general_name && *.mat) 

Is there a way to make something like this work?

Thanks!


Solution

  • Using strcat with general_name and the wildcard character for .mat extensions should work:

    dir(strcat(general_name,'*.mat'))