Faster Looping for Griding/Binning Data

조회 수: 3 (최근 30일)
edward kabanyas
edward kabanyas 2020년 10월 31일
답변: Bruno Luong 2020년 11월 1일
Hi all;
I want to grid my data with following code:
Lat=data(:,7);
Lon=data(:,8);
vprg=data(:,9);
test1=[vprg Lon Lat];
latedges=-10:0.1:10;
lonedges=80:0.1:160;
test2 = zeros(numel(lonedges)-1,numel(latedges)-1);
for i=1:numel(lonedges)-1,
for j=1:1:numel(latedges)-1,
test2(i,j)=size(test1(test1(:,2)>=lonedges(i) & test1(:,2)< lonedges(i+1) & test1(:,3)>= latedges(j) & test1(:,3)< latedges(j+1),:),1);
end
end
However, it is very slow. Probably, there is another option to make it faster. Thank you for your hep.
EK

채택된 답변

Bruno Luong
Bruno Luong 2020년 11월 1일
test2 = histcounts2(test1(:,2),test1(:,3),lonedges,latedges)

추가 답변 (1개)

Sindar
Sindar 2020년 11월 1일
check out discretize

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by