how to find intersection point in arrays with for cycle?
1 view (last 30 days)
Show older comments
ELISABETTA BILLOTTA
on 25 Mar 2022
Commented: ELISABETTA BILLOTTA
on 25 Mar 2022
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 Comments
Accepted Answer
Matt J
on 25 Mar 2022
Edited: Matt J
on 25 Mar 2022
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)
More Answers (0)
See Also
Categories
Find more on Data Type Identification 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!