Skip to content

Instantly share code, notes, and snippets.

@mattgaidica
Created February 19, 2020 16:29
Show Gist options
  • Select an option

  • Save mattgaidica/4d9cef7da95302b289a7989cf10cbd76 to your computer and use it in GitHub Desktop.

Select an option

Save mattgaidica/4d9cef7da95302b289a7989cf10cbd76 to your computer and use it in GitHub Desktop.
Complete_Pero_Master_1.29.20
csvPath = "/Users/matt/Documents/MATLAB/Misc/Complete_Pero_Master_1.29.20_dateFMT.csv";
T = readtable(csvPath);
% augment table
firstCaught = cell(size(T,1),1);
lastCaught = firstCaught;
% new table
new_firstCaught = {};
new_lastCaught = {};
new_mouseID = {};
mouseIDs = unique(T.MouseID);
mouseIDs(strcmp(mouseIDs,'')) = []; % rm empties
for iMouse = 1:numel(mouseIDs)
new_mouseID{iMouse,1} = mouseIDs{iMouse};
mouseRows = find(strcmp(T.MouseID,mouseIDs{iMouse}));
maxDate = max(T.Date(mouseRows));
new_lastCaught{iMouse,1} = maxDate;
minDate = min(T.Date(mouseRows));
new_firstCaught{iMouse,1} = minDate;
for iRow = mouseRows'
firstCaught{iRow,1} = minDate;
lastCaught{iRow,1} = maxDate;
end
end
Tupdated = addvars(T,firstCaught,lastCaught);
Talt = table(new_mouseID,new_firstCaught,new_lastCaught);
writetable(Tupdated,'Complete_Pero_Master_1.29.20_updated_v1.csv');
writetable(Talt,'Complete_Pero_Master_1.29.20_alternative_v1.csv');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment