% Please rename the file extractdata2.m
% extract data from multiple files 2 indices (works for simple index too)

% S Bernard samubernard@gmail.com

vars = who('*BM_*'); % change '*BM_*' as needed
nvar = length(vars);
clear sorted
clear m
clear n

% sort the files with 2 indices of the form 'file_m_n': the index m comes after the first '_' and n after the
% second '_'
for j=1:nvar,
    k=0;
    while (double(vars{j}(end-k))~=95),
        k=k+1;
    end
    n(j)=str2double(vars{j}(end-k+1:end));
    k2=1;
    while (double(vars{j}(end-k-k2))~=95),
        k2=k2+1;
    end
    m(j)=str2double(vars{j}(end-k-k2+1:end-k-1));
end

for i=1:nvar,
    bm_out(m(i),n(i))=eval([vars{i} '(end,7)']); % here the output is column 7: total cell number at tfinal
end