我有来自netCDF文件的纬度LAT
,经度LON
和windspeed。
我想在给定的LAT,LON坐标%Location of Met Mast 51.94341,1.922094888
找到风速。我想分别在RefLAT
和RefLON
矩阵中找到与LAT
和LON
最接近的值。当我在LAT和LON中得到最接近的值时,我将使用地址在这个位置找到我的风速。
当我使用下面的代码时,我希望每个列和行值CLON, CLAT, RLAT
和RLON
都有一个值。相反,我将CLON, CLAT, RLAT
和RLON
作为972个值的数组,我搜索的矩阵LAT
和LON
的大小为848 x 972.
LAT = ncread('wind_level2.nc','latitude');
LON = ncread('wind_level2.nc','longitude');
wind = ncread('wind_level2.nc','wind');
LAT = double(LAT);
LON =double(LON);
%Location of Met Mast 51.94341,1.922094888
RefLAT=51.94341;
LATcalc = abs(LAT - RefLAT);
[RLAT,CLAT]=find(min(LATcalc));
RefLON=1.922094888;
LONcalc = abs(LON - RefLON);
[RLON,CLON]=find(min(LONcalc));`
任何帮助表示赞赏。感谢
按要求提供数据样本:
LAT: 848x972 double:
51.6652641296387 51.6608505249023 51.6564369201660 51.6520233154297 51.6476097106934 51.6431961059570 51.6387825012207
51.6663322448731 51.6619186401367 51.6575050354004 51.6530914306641 51.6486778259277 51.6442642211914 51.6398506164551
51.6674041748047 51.6629867553711 51.6585731506348 51.6541595458984 51.6497459411621 51.6453323364258 51.6409187316895
51.6684722900391 51.6640548706055 51.6596412658691 51.6552276611328 51.6508140563965 51.6464004516602 51.6419868469238
51.6695404052734 51.6651229858398 51.6607093811035 51.6562957763672 51.6518821716309 51.6474685668945 51.6430549621582
51.6706047058106 51.6661911010742 51.6617774963379 51.6573638916016 51.6529502868652 51.6485366821289 51.6441192626953
51.6716728210449 51.6672592163086 51.6628456115723 51.6584320068359 51.6540145874023 51.6496009826660 51.6451873779297
51.6727409362793 51.6683235168457 51.6639099121094 51.6594963073731 51.6550827026367 51.6506690979004 51.6462554931641
51.6738052368164 51.6693916320801 51.6649780273438 51.6605644226074 51.6561470031738 51.6517333984375 51.6473197937012
51.6748695373535 51.6704559326172 51.6660423278809 51.6616287231445 51.6572151184082 51.6528015136719 51.6483840942383
51.6759376525879 51.6715240478516 51.6671066284180 51.6626930236816 51.6582794189453 51.6538658142090 51.6494522094727
LON 848x972 double:
3.04663085937500 3.04491543769836 3.04320049285889 3.04148554801941 3.03977084159851 3.03805613517761 3.03634166717529
3.03959774971008 3.03788304328918 3.03616857528687 3.03445434570313 3.03274011611938 3.03102612495422 3.02931237220764
3.03256440162659 3.03085041046143 3.02913665771484 3.02742290496826 3.02570939064026 3.02399611473084 3.02228283882141
3.02553081512451 3.02381753921509 3.02210426330566 3.02039122581482 3.01867818832397 3.01696562767029 3.01525306701660
3.01849699020386 3.01678419113159 3.01507163047791 3.01335930824280 3.01164698600769 3.00993490219116 3.00822281837463
3.01146292686462 3.00975084304810 3.00803875923157 3.00632715225220 3.00461530685425 3.00290393829346 3.00119256973267
3.00442862510681 3.00271701812744 3.00100588798523 2.99929451942444 2.99758362770081 2.99587273597717 2.99416208267212
2.99739408493042 2.99568319320679 2.99397253990173 2.99226188659668 2.99055147171021 2.98884129524231 2.98713135719299
2.99035930633545 2.98864889144897 2.98693895339966 2.98522901535034 2.98351931571960 2.98180961608887 2.98010015487671
2.98332428932190 2.98161458969116 2.97990512847900 2.97819590568543 2.97648668289185 2.97477769851685 2.97306895256043
答案 0 :(得分:1)
如@excaza所述,find
的语法在您的情况下不合适。如果没有任何比较运算符,find
将采用逻辑比较,并返回包含所有非零元素索引的向量。那不是你想要的。
尝试以下方法:
[RLAT,CLAT]=find(LATcalc<eps);
其中eps
是容错,例如0.00001。
你不能给find
一个完美的平等,因为你正在寻找的数字可能不存在于矩阵中。使用abs(LAT - RefLAT)
,您将拥有两个值之间的差异矩阵。和以前一样,你可能没有一个完美的零,所以你可以找到最接近零的误差容差,以确保捕获最小值。