Average multiple cells in the same lat and lon
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have a 3422x5 (double) numeric matrix A = [Latitude Longitude Biomass lower_boundary upper_boundary]
the lower and upper boundary represent depth
I want to be able to average the biomass across any bins that are in the same exact latitude and longitude. There are several measurements that are in the same lat and lon, so I want to be able to get just one data point for each lat and lon. I also want to be able to calculate the standard deviation of each of those calculations in a different column to keep track of the statistics. Along with this, I would like to keep the lower and upper boundary columns intact with respect to the new, averaged dataset. The duplicated bins all have the same correlated upper and lower boundary
What would be the most efficient way of accomplishing this? I am attaching the matlab file for better reference as to what I am talking about
Any help is appreciated.
Thanks,
Melissa
댓글 수: 0
채택된 답변
Sean de Wolski
2014년 12월 15일
편집: Sean de Wolski
2014년 12월 15일
% Remove nans
idxKeep = ~any(isnan(A(:,1:3)),2);
Akeep = A(idxKeep,:);
% Unique combinations of lat/lon and where they are
[ulatlon,~,idx] = unique(Akeep(:,1:2),'rows');
% Mean of each combination
meanBm = accumarray(idx,Akeep(:,3),[],@mean);
% Combine unique lat/lon combos and meanBm into table
T = table(ulatlon,meanBm,'VariableNames',{'LatLon','MeanBioMass'});
% Show Results
disp(T)
댓글 수: 5
Sean de Wolski
2015년 1월 7일
I guess I'm not clear. Isn't that what idx is above? idx, right now is telling you which row each unique lat/lon is?
So for a given array
x = [1;4;4]
[ux,idxf,idxr] = unique(x)
ux =
1
4
idxf =
1
2
idxr =
1
2
2
So idxr (idx in my original) is telling me where each row came from. idxf, is the first match for the unique values. I think all you need to do is group by idxr, but I'm not completely clear.
Could you provide a small example of what you want with five rows, and just lower boundary?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!