How to bin data in 3 dimensions - 3/4 done but stuck!

조회 수: 4 (최근 30일)
Michael
Michael 2015년 6월 10일
답변: Walter Roberson 2015년 6월 10일
I'm trying to create a 3d matrix gridded as depth x longitude x time with a field of temperature, so that I can select the data based on days, or certain longitude for example. I have done this 2 dimensional, but I am stuck trying to do it 3 dimensional. Can someone help me finish the following code?
% try 3d gridding
x1 = [lonlat(:).v]; % this is longitude
x2 = [date(:).depth];
x3 = [data(:).time];
y = [data(:).temp];
x1rg = [7:0.020:9];
x2rg = [0:5:1000];
x3rg = [min(x3):12:max(x3)]; % not sure if right
for n = 2:size((prcdata_SG502.flight),2);
n
if isempty(prcdata_SG502.hydrography(n).depth') == 0;
lonlat(n).v = prcdata_SG502.flight(n).trajectory_latlon_estimated(:,2)';
end
end
good = ~isnan(x1+x2+x3+y);
[~,whichedge1] = histc(x1(good),x1rg(:)');
[~,whichedge2] = histc(x2(good),x2rg(:)');
[~,whichedge3] = histc(x3(good),x3rg(:)');
bins1 = min(max(whichedge1,1),length(x1rg)-1);
bins2 = min(max(whichedge2,1),length(x2rg)-1);
bins3 = min(max(whichedge3,1),length(x3rg)-1);
bins = (bins2-1)*(length(x1rg)-1)+bins1; % from here onwards I am really stuck!
xpos = ones(size(bins,1),1);
ns = sparse(bins,xpos,1,(length(x1rg)-1)*(length(x2rg)-1),1);
ysum = sparse(bins,xpos,y(good),(length(x1rg)-1)*(length(x2rg)-1),1);
ym = full(ysum)./(full(ns));
yb = ym(bins);
ym = reshape(ym,length(x1rg)-1,length(x2rg)-1)';
thanks, Michael

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 10일
bins = (bins2-1)*(length(x1rg)-1)+bins1; % from here onwards I am really stuck!
bins = sub2ind([length(x1rg), length(x2rg), length(x3rg)], bins1, bins2, bins3);

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by