Sort image name files in Matlab?

I have two different types of dicom (medical image files) in the same folder. I want to sort them into two different arrays, one for SE006 and one for SE014.

    MR-ST001-SE006-0001.dcm... MR-ST001-SE006-0021.dcm  
    MR-ST001-SE014-0001.dcm... MR-ST001-SE014-0013.dcm 

I am using something like this code below, but it is wrong. I think I have syntax errors.

  if image == 'MR-ST001-SE006-%4.4.dcm'
      SE006(end+1) = image 
  if image == 'MR-ST001-SE014-%4.4.dcm'
      SE014(end+1) = image 

Anyone have any tips for improving this to make it work?

+3
source share
2 answers

You can read all the files in an array of cells using DIR and then use CELLFUN to vectorize the solution from @jonsca.

files = dir('MR-ST001-SE*.dcm');
dcmnames = {files(:).name}';
idx06 = ~cellfun(@isempty,strfind(dcmnames,'SE006'));
idx14 = ~cellfun(@isempty,strfind(dcmnames,'SE014'));
SE006 = dcmnames(idx06);
SE014 = dcmnames(idx14);
+4
source

strfind() isempty() if/else if .

 if ~isempty(strfind(yourstr,'SE006'))
     #add it to your list
 end
+2

All Articles