Prev: timer object communication via socket
Next: code error
From: Sal on 10 Jul 2010 20:07 Hello everyone, I am trying to write a function that gets certain data values from netcdf file and then, using 2D interpolation, calculates the value of data in between the coordinates. The syntax I am using is as follows; ZI = interp2(X,Y,Z,XI,YI) data_set = -5.1695 -5.6024 -5.3846 -5.8743 (data_set is 4x1 and contains the data obtained from netcdf file) x_set = [0,25,60,80]; y_set = [0,25,60,80]; (both x_set and y_set are 1x4) data1 = interp2(x_set,y_set, data_set, 17.728, 12.664) %17.728 is distance along x %12.664 is distance along y At first, I had trouble synchronising the lengths of x and y_sets, and data_set arrays. i kept getting error messages of "The lengths of the X and Y vectors must match Z." This was due to the fact that intially, I had x_set and y_set equal to [0:20:80] 5x1 arrays which are not of the same length as data_set. (4x1) However, when i changed x_set and y_set to the ones as shown above, i started getting the error: Subscript indices must either be real positive integers or logicals. I must be making a mistake somewhere but can't seem to figure out?? should i instead try ID interpolation? any ideas/pointers are most appreciated. thank you Salman
From: us on 10 Jul 2010 20:24 "Sal " <salman.hafeez(a)mail.mcgill.ca> wrote in message <i1b1v9$618$1(a)fred.mathworks.com>... > Hello everyone, > I am trying to write a function that gets certain data values from netcdf file and then, using 2D interpolation, calculates the value of data in between the coordinates. The syntax I am using is as follows; > > ZI = interp2(X,Y,Z,XI,YI) > > > data_set = > -5.1695 > -5.6024 > -5.3846 > -5.8743 > (data_set is 4x1 and contains the data obtained from netcdf file) > > x_set = [0,25,60,80]; > > y_set = [0,25,60,80]; > (both x_set and y_set are 1x4) > > data1 = interp2(x_set,y_set, data_set, 17.728, 12.664) > %17.728 is distance along x > %12.664 is distance along y > > At first, I had trouble synchronising the lengths of x and y_sets, and data_set arrays. i kept getting error messages of "The lengths of the X and Y vectors must match Z." > This was due to the fact that intially, I had x_set and y_set equal to [0:20:80] 5x1 arrays which are not of the same length as data_set. (4x1) > > However, when i changed x_set and y_set to the ones as shown above, i started getting the error: Subscript indices must either be real positive integers or logicals. > > I must be making a mistake somewhere but can't seem to figure out?? should i instead try ID interpolation? any ideas/pointers are most appreciated. > > thank you > Salman a hint: - your Z, ie, DATA_SET, must be 2D... help interp2; % <- look at it carefully(!)... us
From: Sal on 10 Jul 2010 21:15 Hi us, Thank you for the tip..i changed data_set to 2x2 and made x_set and y_set into a 1x2 array, and it worked. However, whenever I change the order of values stored in the data_set array, i get a different interpolated value. (however, the difference isn't very large, ranging from -5.31 to -5.41 and -5.59 ) Each of the values stored in data_set are actually data values, obtained on set of specific coordinates on a grid within the netcdf file. I am using 2D interpolation to find values for set of points that fall within the boundary of specified coordinates. (42,25) = -5.6024 (43,25) = -5.8743 (42,24) = -5.1695 (43,24) = -5.3846 For this case, I was trying to find the data value at (42.728, 24.664) and the scale used for grid is 1:80 My main concern right now is how should i store the data values (obtained from netcdf file, for specific coordinates) within the data_set array? should it be as follows data array = [ (42,25) (43,25) (42,24) (43,24) ] or some other way?? Please let me know Salman
From: Bruno Luong on 11 Jul 2010 08:32 "Sal " <salman.hafeez(a)mail.mcgill.ca> wrote in message <i1b5va$4ar$1(a)fred.mathworks.com>... > > My main concern right now is how should i store the data values (obtained from netcdf file, for specific coordinates) within the data_set array? should it be as follows > > data array = [ (42,25) (43,25) > (42,24) (43,24) ] > > or some other way?? > Please let me know The INTERP2(x,y,Z, ...) assumes the Z data is generated meshgrid-like, i.e., first dimension corresponds to y, second dimension to x. This is written in the doc. Of course you could also swap x/y when calling INTERP2. Bruno
|
Pages: 1 Prev: timer object communication via socket Next: code error |