MATLAB Cell Array - Average two values if another column matches
I have a cell array in which some of the entries have two data points. I
want to average the two data points if the data were collected on the same
day.
The first column of cell array 'site' is the date. The fourth column is
the data concentration. I want to average the fourth column if the data
comes from the same day.
For example, if my cell array looks like this:
01/01/2011 36-061-0069 1 10.4
01/01/2011 36-061-0069 2 10.1
01/04/2011 36-061-0069 1 7.9
01/05/2011 36-061-0069 1 13
I want to average the fourth column (10.4 and 10.1) into one row and leave
everything else the same.
Help? Would an if elseif loop work? I'm not sure how to approach this
issue, especially since cell arrays work a little differently than
matrices.
for it = 1:size(CellArray,1)
ReplyDeletesum = sum + cellArray{it}(4) % or .NameOfColumn if it a cell containing struct
end
mean(sum)
You can try this sir.
khanhvuongtuan1@gmail.com - Working at ComponentPro