Problem with Arithmetic mean/Theissen method with matlab

조회 수: 1 (최근 30일)
Pai-Feng Teng
Pai-Feng Teng 2018년 9월 30일
%Currently I am working on the assignment and I have difficulty on making the code work. The problem is that "Index exceeds matrix dimensions." at "indx= index(pos);"
%Here it my code
%The shape of a drainage basin can be approximate by a polygon whose
%vertices are located at the following coordinates: (5,5), (-5,5), (-5,-5),
%(0,-10), (5,-5)
%Step 1: Catchment Area Coordinates
X = input('X=');
Y = input('Y=');
plot(X,Y,'r','Linewidth',3)
%Step 2: set up gage data
x=[ 7 3 -2 -10 -3 -7 2 2 0]';
y=[ 4 4 5 1 -3 -7 -3 -10 0]';
gages = [x ...
y];
hold on
scatter(x,y,'b','Marker','*')
text([7; 3; -2; -10; -3; -7; 2; 2; 0],[4; 4; 5; 1; -3; -7; -3; -10; 0],['1';'2';'3';'4';'5';'6';'7';'8';'9'],...
'HorizontalAlignment','right',...
'FontSize',12,...
'FontName','Impact');
voronoi(x(:),y(:))
%3. Calculation of Grid Points
m = input('m = ');
n = input('n = ');
for a=1:m
for b=1:n
gx(a,b)=b;
gy(b,a)=b;
scatter(a,b,...
'r','Marker','.')
end
end
p = cat(2,gx,gy);
%4. grid points
grdpts = (m*n);
r = reshape(p,grdpts,2);
index = 1:grdpts;
for d1 = 1:9
for d2 = 1:grdpts
distn = pdist2(gages,r);
end
[~, pos] = min(distn);
indx= index(pos);
end
%5. Nearest Gage to each grid point
numb = zeros(grdpts,1);
for g=1:9
numb = find(indx==g);
wt(g,1)= length(numb);
end
numb;
wt;
%6. (a) the arithmetic mean method
aritm_avg_rainfall = mean(rainfall);
%6. (b) The theissen method
theisswts = wt./grdpts;rainfall = input('rainfall =');
Currently

답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by