I am working with large datasets which I am subsetting into various categories and saving as smaller files. What I am doing right now is working but it is quite time consuming and error prone, as it involved a lot of copy and paste.
For example, I have many files I have split into those with boats and those without boats. I then split those into season. Would there be a faster way to do this where I apply the same command to prescribed set of variables?
%% Comparisons... Season using water temp
boatsAbsent_t=boatsAbsent.Var1; %time variables
[BA_spring, BA_summer, BA_autumn, BA_winter]=indexSeasons(boatsAbsent_t); %index times into seasons
boatsPresent_t=boatsPresent.Var1; [BP_spring, BP_summer, BP_autumn, BP_winter]=indexSeasons(boatsPresent_t); %Subset PSD outputs and write to file
S=withtol(BA_spring,seconds(1));BA_spring=boatsAbsent(S,:);writetable(timetable2table(BA_spring),... fullfile(folder,strcat(site,'_PSD_boatsAbsent_Spring.csv')));S=withtol(BA_summer,seconds(1));BA_summer=boatsAbsent(S,:);writetable(timetable2table(BA_summer),... fullfile(folder,strcat(site,'_PSD_boatsAbsent_Summer.csv')));S=withtol(BA_autumn,seconds(1));BA_autumn=boatsAbsent(S,:);writetable(timetable2table(BA_autumn),... fullfile(folder,strcat(site,'_PSD_boatsAbsent_Autumn.csv')));S=withtol(BA_winter,seconds(1));BA_winter=boatsAbsent(S,:);writetable(timetable2table(BA_winter),... fullfile(folder,strcat(site,'_PSD_boatsAbsent_Winter.csv'))); S=withtol(BP_spring,seconds(1));writetable(timetable2table(BP_spring),... fullfile(folder,strcat(site,'_PSD_boatsPresent_Spring.csv')));S=withtol(BP_summer,seconds(1));writetable(timetable2table(BP_summer),... fullfile(folder,strcat(site,'_PSD_boatsPresent_Summer.csv')));S=withtol(BP_autumn,seconds(1));writetable(timetable2table(BP_autumn),... fullfile(folder,strcat(site,'_PSD_boatsPresent_Autumn.csv')));S=withtol(BP_winter,seconds(1));writetable(timetable2table(BP_winter),... fullfile(folder,strcat(site,'_PSD_boatsPresent_Winter.csv')));
Best Answer