how to find intersection point in arrays with for cycle?
조회 수: 1 (최근 30일)
이전 댓글 표시
I built such a grid:
longrd=0:0.1:40;
latgrd=25:0.1:65;
limlon=[min(longrd),max(longrd)];
limlat=[min(latgrd),max(latgrd)];
ic=0;
for i=1:length(longrd)
for j=1:length(latgrd)
ic=ic+1;
lonlatgrd(ic,1)=longrd(i);
lonlatgrd(ic,2)=latgrd(j);
end
end
and such a figure where XX, YY and ZZ are 401x401 double and prob is 1x160801 double.
figure()
for i=1:length(longrd)
for j=1:length(latgrd)
XX(i,j)=longrd(i);
YY(i,j)=latgrd(j);
isel1=find(lonlatgrd(:,1)==longrd(i));
isel2=find(lonlatgrd(isel1,2)==latgrd(j));
isel=isel1(isel2);
ZZ(i,j)=prob(isel);
end
end
contourf(XX,YY,ZZ)
now, from this for loop I have to extract a particular number. Knowing the value of lonP and latP, they must find them inside XX and YY respectively. their point of intersection then I have to find it inside the variable ZZ and I have to visualize it.
lonP= 13.5;
latP= 41.9;
for i1=1:length(XX);
for j1=1:length(YY);
for z1= 1:length(ZZ);
isel1=find(XX(:,:)==lonP(i1));
isel2=find(YY(:,:)==latP(j1));
isel3=intersect(isel1,isel2);
values=find(ZZ(:,:)==isel3(z1));
end
end
end
I wrote this for loop like this but it doesn't work. isel2 is an empty set and there is thir error "Index exceeds the number of array elements. Index must not exceed 0".
Can anyone help me?
댓글 수: 0
채택된 답변
Matt J
2022년 3월 25일
편집: Matt J
2022년 3월 25일
isel2 is an empty set
Sure, why not? Nothing in your code reveals why lonP= 13.5, latP= 41.9 are expected to coincide exactly with one of you grid points. I have the vague impression, though, that you are reinventing griddedInterpolant. Does this do what you want?,
longrd=0:0.1:40;
latgrd=25:0.1:65;
F=griddedInterpolant({longrd,latgrd},ZZ);
lonP= 13.5; latP= 41.9;
values = F(lonP,latP)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!