Question

I'm trying to get a path to all the jpeg files in a directory including 'fig'. This code below gets all the jpeg files in the directory, however does not exclude any 'rft' labeled files.

base_directory = '/home/user/data/';
directories = dir([base_directory,'/*.jpg']);
filenames = directories;

An example of the directory is

goblet_fig_2004_03_07.jpg
goblet_rft_2004_03_07.jpg
goblet_fig_2004_11_02.jpg
goblet_rft_2004_11_02.jpg

Any help is appreciated.

After help this is my complete code, Notice 'fig.jpg', was the answer I was looking for

base_directory = '/home/user/data/';                                
directories = dir([base_directory,'*fig*.jpg']);                             
filenames = directories;                                                   
for fileIndex = 1: length(filenames)  
    image = imread([base_directory,'/',filenames(fileIndex).name]);    
end                                                                                                                        
Était-ce utile?

La solution 2

filenames = dir('*fig*.jpg')

I have tried it on Windows, not Linux, but it should work.

Autres conseils

A simple answer is this:

directories = [dir('*.fig'); dir('*.jpg')]

You can try using regular expressions for instance

directories = {'goblet_fig_2004_03_07.jpg'
'goblet_rft_2004_03_07.jpg'
'goblet_fig_2004_11_02.jpg'
'goblet_rft_2004_11_02.jpg'};

directories(~cellfun('isempty',regexp(directories,'fig')))

returns

ans = 

    'goblet_fig_2004_03_07.jpg'
    'goblet_fig_2004_11_02.jpg'

Other functions such as findstr probably work too.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top