Hi,
point1 = (latitude, longitude) % in degrees
point2 = (latitude, longitude)point3 = (latitude, longitude)interpoint = (latitude, longitude)
point1,2,3 are stations where data is collected. point1,2,3 form a triangle and "interpoint" is located inside this triangle. "interpoint" is also a station.
P1 = [123, 345, 341; 986, 665, -645; 543, 86, -40; 0, 100, 0; .....cont.]P2 = [-123, 381, 741; 986, 0, 645; 543, -86, 10; 12, 0, 54; ....cont.]P3 = [723, 455, 224; -958, 0, 654; 743, 46, 11; 23, 0, 68; ....cont]
P4 are the values that I want to predict.
P1 are the values from point1 and P2 from point2 and so on.
As the output, I'm expecting the P4 matrix.
I experimented with interp2 and griddedInterpolant but the general error was assigning for e.g, point1 as the coordinates of P1 matrix (the whole thing) and expressing "interpoint" as the coordinates of the P4 values is to be interpolated.
Also with griddedInterpolant I get error, "Interpolation requires at least two sample points in each dimension" when running the following.
[X,Y] = ndgrid(lon1:lon3,lat3:lat1); % lon1 is the longitude of point1, etc..
V = P1;F = griddedInterpolant(X,Y,V);[Xq,Yq] = ndgrid(lat4,lon4);Vq = F(Xq,Yq);mesh(Xq,Yq,Vq);
scatteredInterpolant too ended in a disaster because I do not know how to call it to work. I'v been reading everything I can find on internet to learn how to get the output as a whole matrix of interpolated data, but no help.
Matlab keeps screaming that each cell needs a location but how can I tell it that all cells of P1 have the same location. To circumnavigate this issue I tried repmat location coordinates to the size of P1 but then the error was identical locations identified or something along those lines..
Anyways I think there IS a way but I can't seem to find it.
Alternatively , I followed a mathematical approach to calculate a single value at P4 and it's working.
Latitude and longitude converted to radians and then solve the following 3 equations (for a sample cell at row 8, column 4.
[S1, S2, S3] = solve(a0+(a1.*(lat1))+(a2.*(lon1)) == P1(8,4), a0+(a1.*(lat2))+(a2.*(lon2)) == P2(8,4), a0+(a1.*(lat3))+(a2.*(lon3)) == P3(8,4), a0, a1, a2);SQ = S1+(S2.*(latq))+(S3.*(lonq)); % latq, lonq are the values from interpoint.
SQ is P4(8,4).
How do I get Matlab to run this in a loop and find every single value of SQ excluding where any of the input values are zero. i.e., if for a given cell the value in either P1, P2 or P3 is zero there should not be a result for that cell. Because 0 in my data set are artificial and thus the result would be wrong.
I don't like this method because the precision could get very low.
I really would like to compare this with Matlab's scatteredInterpolant or interp2 only if I know how to..
what's the best method to approach this?
Thanks!
Best Answer