MATLAB: Find the file that gives minimum standard deviation

data importerror

Hello,
I have written a piece of code in the following to select some files in order to find the difference between two dat files. So far, I have managed to take a standard difference between different files but my goal is to be able to find which file data gives the minimum error with respect to the reference data.
I am not sure how to proceed. Any help would be highly appreciated.
ref_path='C:Desktop\prism\Au_707_G0_L880';
ref_file = fullfile(ref_path,'*.dat');
ref_filelist= dir(ref_file);
ref_filename = {ref_filelist.name};
for l=1:numel(ref_filename)
ref_data(:,l)=load(ref_filename{l});
end
file_path='C:\Desktop\prism\Au_707_G00_L880';
file = fullfile(file_path,'*.dat');
filelist=dir(file);
k=1;
for j=1:numel(ref_filelist)
for i =1:numel(filelist)
filenames={filelist.name};
if strfind(filenames{i}, '_RS')
A(:,i)=load(filenames{i});
diff(:,k)=ref_data(:,j)-A(:,i);
std_diff(:,k)=std(diff(:,k),1);
k=k+1;
end
end
end

Best Answer

  • associated_files = {};
    for j=1:numel(ref_filelist)
    for i =1:numel(filelist)
    filenames={filelist.name};
    if strfind(filenames{i}, '_RS')
    A(:,i)=load(filenames{i});
    data_diff(:,k)=ref_data(:,j)-A(:,i);
    std_diff(:,k)=std(data_diff(:,k),1);
    associated_files{k} = filenames{i};
    k=k+1;
    end
    end
    end
    But then you have the question as to what "minimum error" is. One way of expressing it would be:
    err = sum(data_diff.^2);
    [best_err, erridx] = min(err);
    best_file = associated_files{erridx};