% folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\AC_20220225_Fluo4Direct_Fluo4BaptaNeud32_plate96_out\AC_20220225_Fluo4Direct_Fluo4BaptaNeud32_plate96_out';
% Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220225_Fluo4Direct_Fluo4BaptaNeud32_plate96_out.csv'
% folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\AC_20220225_Fluo4Direct_BaptaNeud32__newhoechst_out\AC_20220225_Fluo4Direct_BaptaNeud32__newhoechst_out';
% Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220225_Fluo4Direct_BaptaNeud32__newhoechst_out.csv'
% folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220812_Fluo4Direct_mat_iono_diff622newhoechst_out\AC_20220812_Fluo4Direct_mat_iono_diff622newhoechst_out';
% Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220812_Fluo4Direct_mat_iono_diff622newhoechst_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220422_Fluo4Direct_mat3newhoechst_out\AC_20220422_Fluo4Direct_mat3newhoechst_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220422_Fluo4Direct_mat3newhoechst_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220422_Fluo4Direct_mat2_out\AC_20220422_Fluo4Direct_mat2_out';
% Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220422_Fluo4Direct_mat2_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220422_Fluo4Direct_mat1_out\AC_20220422_Fluo4Direct_mat1_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220422_Fluo4Direct_mat1_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220422_Fluo4Direct_mat4_out\AC_20220422_Fluo4Direct_mat4_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220422_Fluo4Direct_mat4_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220812_Fluo4Direct_mat_bapta_egta_diff622_out\AC_20220812_Fluo4direct_mat_bapta_egta_diff622_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220812_Fluo4direct_mat_bapta_egta_diff622_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\20220812_Fluo4Direct_mat_iono_diff622_out\AC_20220812_Fluo4Direct_mat_iono_diff622_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220812_Fluo4Direct_mat_iono_diff622_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\AC_20220311_Fluo4Direct_mat_out\AC_20220311_Fluo4Direct_mat_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220311_Fluo4Direct_mat_out.csv'
%folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\AC_20220325_Fluo4Direct_mat_out\AC_20220325_Fluo4Direct_mat_out';
%Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20220325_Fluo4Direct_mat_out.csv'
%Now data folders have similar names, just change one letter
folder = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\96wells_Bapta_etc\AC_20221126_Fluo4direct_mat_iono4_out\AC_20221126_Fluo4direct_mat_iono4_out';
Outputfile = 'S:\HCS_Platform\Data\AxelChemla\CaNeuronsReinhard\Fluo4Folder2Summary\AC_20221126_Fluo4direct_mat_iono4_out.csv'

files = struct2table(dir(folder))
files = files(files.isdir == 0,:)
csv_files = regexp(files.name, '(.*).csv', 'tokens');
csv_files = cellfun(@(x) ~isempty(x), csv_files);
files = files(csv_files, :)

for i = 1:height(files)
    fileThis = [files{i,"folder"}{:}, filesep, files{i,"name"}{:}];
    if i == 1
        dataThisTrack = readtable(fileThis);
        dataThisTrack.Properties.VariableNames = {files{i,"name"}{:}(1:end-4)};
        dataThisCV8000run = dataThisTrack;
    else
        dataThisTrack = readtable(fileThis);
        dataThisTrack.Properties.VariableNames = {files{i,"name"}{:}(1:end-4)};
        dataThisCV8000run = [dataThisCV8000run, dataThisTrack];
    end
end

writetable(dataThisCV8000run, Outputfile)