Hi everyone,
I currently have an n x 6 numeric matrix called meta. where site = meta(:,1), datenum = meta(:,2), variables = meta(3:10). There are numerous datenums that are identical as a consequence of looking at multiple sites over the same time period. I would like to sum each variable individually in accordance to the datenum. Below is the code that I have so far. I'm attempting to make a loop (see code below), however it keeps returning an empty index when I run the date_index=find(dates==i) line. I know that the dates will definitely match i (the unique dates), so confused as to why it's empty.
Equally, perhaps my loop within the loop needs tweaking? I'm very new to Matlab, so any help would be much appreciated. Also happy to provide further explanation if needed. Thank you in advance!
% Plot 1: Computing summary of sites by datenum
meta=xlsread('Incidents_and_HeadcountsUpdated.xlsx',4,'A2:L2123');dates=(meta(:,2))unique_dates=unique(dates)%Sum of each individual variable per unique datenum
for i = 1:length(unique_dates), date_index = find(dates==i); for j = meta(3:10), %Columns for each incident type (rip, wind, tcur and tcut, total inc) and headcount (beach,water,total)
data_sums(i,1)=i; data_sums(i,j-1) = sum(meta(index,j)); end end
Best Answer