0001 function zp=griddata_grid_to_mesh_completer(x_m,y_m,u,index,x,y,zp);
0002
0003
0004
0005
0006
0007 pos=find(isnan(u));
0008 for n=1:100,
0009 pos=find(isnan(u));
0010 u(pos)=u(pos+1);
0011 end
0012
0013 imagesc(u)
0014 break
0015
0016 zp=zeros(length(x),1);
0017 for n=1:length(x),
0018 if mod(n,100)==0,
0019 disp(['Count is ' num2str(n/length(x)*100)]);
0020 end
0021
0022 pos1=find((x_m-x(n))<0);
0023 pos2=find((x_m-x(n))>0);
0024 pos3=find((y_m-y(n))<0);
0025 pos4=find((y_m-y(n))>0);
0026
0027 if (isempty(pos1) | isempty(pos2) | isempty(pos3) | isempty(pos4)),
0028 out_of_bounds=1;
0029 else
0030 out_of_bounds=0;
0031 end
0032
0033 if out_of_bounds==0,
0034
0035 pos1=find((x_m-x(n))<0);
0036 pos2=find((x_m-x(n))>0);
0037 x_bound=[pos1(length(pos1)) pos2(1)];
0038
0039 pos1=find((y_m-y(n))<0);
0040 pos2=find((y_m-y(n))>0);
0041 y_bound=[pos1(length(pos1)) pos2(1)];
0042
0043
0044
0045
0046
0047 A=[x_m(x_bound(1)) y_m(y_bound(1))]';
0048 u_A=u(x_bound(1),y_bound(1));
0049 B=[x_m(x_bound(2)) y_m(y_bound(1))]';
0050 u_B=u(x_bound(2),y_bound(1));
0051 C=[x_m(x_bound(2)) y_m(y_bound(2))]';
0052 u_C=u(x_bound(2),y_bound(2));
0053 D=[x_m(x_bound(1)) y_m(y_bound(2))]';
0054 u_D=u(x_bound(1),y_bound(2));
0055
0056
0057
0058 res=(D(2)-B(2))*x(n)+(B(1)-D(1))*y(n)+D(1)*B(2)-D(2)*B(1);
0059 if res>0,
0060 xx=[B(1) C(1) D(1)];
0061 yy=[B(2) C(2) D(2)];
0062 uu=[u_B u_C u_D];
0063 ind=[1 2 3];
0064 else
0065 xx=[A(1) B(1) D(1)];
0066 yy=[A(2) B(2) D(2)];
0067 uu=[u_A u_B u_D];
0068 ind=[1 2 3];
0069 end
0070
0071
0072 alpha=zeros(1,3);
0073 beta=zeros(1,3);
0074 gamma=zeros(1,3);
0075 X=inv([xx(ind(1,:))' yy(ind(1,:))' ones(3,1)]);
0076 alpha(1,:)=X(1,:);
0077 beta(1,:)=X(2,:);
0078 gamma(1,:)=X(3,:);
0079
0080 if length(find(isnan(uu)))==0,
0081 zp(n)=sum(uu.*(alpha.*x(n)+beta.*y(n)+gamma));
0082 else
0083 if length(find(~isnan(uu)))==0,
0084 zp(n)=NaN;
0085 else
0086 pos=find(~isnan(uu));
0087 zp(n)=uu(pos(1));
0088 end
0089 end
0090
0091 else
0092 zp(n)=NaN;
0093 end
0094
0095
0096 end
0097
0098