date_used=datevec(datenum(1982,1,1):datenum(2022,12,31));
land_index=isnan(nanmean(mhw_ts,3));
mhwday_month=NaN(size(mhw_ts,1),size(mhw_ts,2),12);
mhwint_month=NaN(size(mhw_ts,1),size(mhw_ts,2),12);
index_used=date_used(:,2)==i;
mhwday_month(:,:,i)=sum(~isnan(mhw_ts(:,:,index_used)),3,'omitnan')./(2022-1982+1);
mhwint_month(:,:,i)=mean(mhw_ts(:,:,index_used),3,'omitnan');
mhwday_month(repmat(land_index,1,1,12))=nan;
mhwday_seas=NaN(size(mhw_ts,1),size(mhw_ts,2),4);
mhwint_seas=NaN(size(mhw_ts,1),size(mhw_ts,2),4);
index_used=ismember(date_used(:,2),seas(i,:));
mhwday_seas(:,:,i)=sum(~isnan(mhw_ts(:,:,index_used)),3,'omitnan')./(3*(2022-1982+1));
mhwint_seas(:,:,i)=mean(mhw_ts(:,:,index_used),3,'omitnan');
mhwday_seas(repmat(land_index,1,1,4))=nan;