filename = ('PM2.5_NY_2012.csv'); % PM2.5 88101 data from NY in the year 2012
% Use functions created by read_mixed_csv.m to read in
data = read_mixed_csv(filename,','); % Creates cell array of data
data = regexprep(data, '^"|"$',''); % Gets rid of double quotes at the start and end of the string
% Sort data based on date (Column 1)
[Y,I] = sort(data(:,1)); % Create 1st column sorted
site_sorted = data(I,:); % Sort the entire array
u_id=unique(site_sorted(:,2)); % get unique id
for i=1:length(u_id)
idx=ismember(site_sorted(:,2),u_id{i}); % extract index where the second column matches the current id value
site_data = site_sorted(idx,:);
save([u_id{i} '.mat'],'site_data');
end
this should do it?