简体   繁体   中英

MATLAB dir command not working properly

I have a folder containing 9 .htk files. I need to use "dir", and then "readhtk" in a loop to import them to MATLAB, but DIR appears to give 10 files instead of 9! here is my code:

htkfiles = dir('/Users/Desktop/Acsegment/mfcdir/*.htk');
nhtkfiles = length(htkfiles); % 10!!! It should be 9 tough!
data = cell(nhtkfiles,2);
for k = 1:nhtkfiles
    b(k,1) = strcat({'/Users/Desktop/Acsegment/mfcdir/'},{htkfiles(k,1).name});
    eval(['data{k,1} = readhtk(b{k,1});']);
end

When looking at the filenames in htkfiles, I have them like this:

  htkfiles(1,1).name = '.htk'
  htkfiles(2,1).name = 'fadg0_si1279.htk'
  htkfiles(3,1).name = 'fadg0_si1909.htk'
  htkfiles(4,1).name = 'fadg0_si649.htk'
  htkfiles(5,1).name = 'fadg0_sx109.htk'
  htkfiles(6,1).name = 'fadg0_sx19.htk'
  htkfiles(7,1).name = 'fadg0_sx199.htk'
  htkfiles(8,1).name = 'fadg0_sx289.htk'
  htkfiles(9,1).name = 'fadg0_sx379.htk'
  htkfiles(10,1).name = 'faks0_si943.htk'

Comparing to what I see in that folder, the first file is not supposed to be there! Anyone got any ideas why Im getting one extra file?

As mentioned in the comments: the dir command actually works properly, there just happens to be a hidden file.

These files starting with a dot could be removed from your list like so:

d=dir;
d(strncmp({d.name},'.',1))=[];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM