문제

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                                                                                                                        
도움이 되었습니까?

해결책 2

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

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top