Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Michael
Michael le 10 Juin 2015
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

Réponses (1)

Walter Roberson
Walter Roberson le 10 Juin 2015
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);

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by