Let's say you're starting with the spreadsheet version of something like this:
Time,Species,Size,Direction
10/25/2016 10:11:12,chinook salmon,65cm,up
10/25/2016 13:14:15,chinook salmon,66cm,up
10/25/2016 16:17:18,steelhead trout,67cm,down
First read the data in as a table.
>> T = readtable('fishData.csv')
T =
Time Species Size Direction
___________________ _________________ ______ _________
10/25/2016 10:11:12 'chinook salmon' '65cm' 'up'
10/25/2016 13:14:15 'chinook salmon' '66cm' 'up'
10/25/2016 16:17:18 'steelhead trout' '67cm' 'down'
In recent versions of MATLAB, that first column in the file will automatically be a datetime variable in T, in earlier versions you can convert it. The other three come in as strings, it will be more convenient to have two categoricals and a numeric.
>> T.Species = categorical(T.Species);
>> T.Size = str2double(strrep(T.Size,'cm',''));
>> T.Direction = categorical(T.Direction);
>> T
T =
Time Species Size Direction
___________________ _______________ ____ _________
10/25/2016 10:11:12 chinook salmon 65 up
10/25/2016 13:14:15 chinook salmon 66 up
10/25/2016 16:17:18 steelhead trout 67 down
Now you can select or sort on time, species, size or direction, such as
>> T(T.Species == 'chinook salmon',:)
ans =
Time Species Size Direction
___________________ ______________ ____ _________
10/25/2016 10:11:12 chinook salmon 65 up
10/25/2016 13:14:15 chinook salmon 66 up
You can also get daily counts by species. If you also want something like the mean size, varfun would be one way to do that:
>> T.Day = dateshift(T.Time,'start','day'); T.Day.Format = 'MM/dd/yyyy';
>> varfun(@mean,T,'GroupingVariables',{'Day' 'Species'},'InputVariables','Size')
ans =
Day Species GroupCount mean_Size
__________ _______________ __________ _________
10/25/2016 chinook salmon 2 65.5
10/25/2016 steelhead trout 1 67
If you have access to R2016b, you probably want to look at the new timetable type, which makes things like daily counts simpler, using synchronize.
Hope this helps.