title: MATLAB Save a .mat file into smaller files based on one column being in common
body: <p>I have a cell array with 22 columns. I want to read through the cell array and separate it into different .mat files based on column 2 (the site in string format). Basically, the data has information from one year for sites all over New York. I want to save the data for each site separately (find the rows with the same column 2 and save them). </p>
  
  <p>I'd also like to convert the .mat file to a netcdf file so people who don't use MATLAB can also read it, but first, I just need to be able to separate the cell array without manually finding each specific string and saving it. </p>
  
  <p>The data is this file: <a href="https://www.dropbox.com/sh/li3hh1nvt11vok5/4YGfwStQlo" rel="nofollow">https://www.dropbox.com/sh/li3hh1nvt11vok5/4YGfwStQlo</a></p>
  
  <p>I use this script to read in the file and then sort it by the date (column 1):</p>
  
  <pre><code>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
  </code></pre>
  
  <p>So now it's a cell array. How can I save all the data with the same 2nd column into a different file? Would using 'unique' or 'find' be useful? I know how to do it by searching for a specific string and saving all that have that string, but since there are a lot of sites, is there a way to automate this?</p>
  
  <p>Would using unique to make a list of the filenames and then looping through to create a file using that list work? I'm still relatively new to programming, so I don't know what I can do.</p>