how to find intersection point in arrays with for cycle?
Show older comments
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?
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!