function [feature_counts] = read_num_features_dir(data_dir,feature_name)
feature_files = dir(strcat(data_dir,'\'));

curr_files = [];
imgs       = [];
subs       = [];

for i = 1:length(feature_files)
   curr_str = feature_files(i).name;
   
   if (curr_str == "." || curr_str == "..")
      continue; 
   end
   
   extension = curr_str(end-3:end);
   name      = curr_str(1:end-4);
   
   %only process .csvs
   if (~strcmp(extension,'.csv'))
       continue;
   end
   
   %check if feature is in name (or in right spot) skip if not
   if (~contains(name,feature_name))
       continue;
   end
   
   %make a list of unique subjects
   sub_pattern = '_R*\d*\d*\d_';
   [sub_startIndex,sub_endIndex] = regexp(name,sub_pattern);
   
   sub_id = name(sub_startIndex:sub_endIndex);
   
   %check if this sub is new or not, if so add to imgs array
   if (isempty(subs) || ~any(contains(subs,sub_id)))
       subs = [subs;string(sub_id)];
   end
   
   %use regex, look for R followed by up to 3 digits for img_idx
   img_pattern = '_R*\d*\d*\d_';
   [sub_startIndex,sub_endIndex] = regexp(name,img_pattern);
   
   img_idx = name(sub_startIndex:sub_endIndex);
   
   %check if this img_idx is new or not, if so add to imgs array
   if (isempty(imgs) || ~any(contains(imgs,img_idx)))
       imgs = [imgs;string(img_idx)];
   end
   
   %add file string to list
   curr_files = [curr_files string(curr_str)];
   
end

%first: init output cell array
num_imgs  = length(imgs);
num_subs  = length(subs);

feature_counts = cell(num_imgs,length(num_subs));

%second: loop over all images 
for i = 1:num_imgs
    curr_img_str = imgs(i);
    curr_img     = str2double(curr_img_str{1}(3:end-1));
    
    %find all files for this image (one for each subject that viewed it) 
    curr_subs = curr_files(contains(curr_files,curr_img_str));
    
    
    
    %loop over curr_sub csvs
    for j = 1:length(curr_subs)
        curr_file = curr_subs(j);
        
        %todo: extract subject id
        sub_pattern = '_P*\d*\d*\d_';
        [startIndex,endIndex] = regexp(curr_file,sub_pattern);
        %want just the digits
        curr_sub = str2double(curr_file{1}(startIndex+2:endIndex-1));
        
        %load the csv from curr_file 
        curr_data = csvread(strcat(data_dir,'\',curr_file));
        
        num_features = size(curr_data,1);
        
        %concatenate into a data matrix 
        feature_counts{curr_img,curr_sub} = num_features;
    end
end
        
end

