Right now this is the code I have, but I get a lot of NaN's in the data because I am still able to search through the entire row and column of A, even if there is only one non NaN in that row and column
NaN = isnan(A); %360x720
[row col] = find(NaN==0); %62641x1 row, 62641x1 col
row = unique(row);
col = unique(col);
lon_A = lon(col);
lat_A = lat(row);
[IDX_lat,D_lat] = knnsearch(lat_A,lat_B);
[IDX_lon,D_lon] = knnsearch(lon_A,lon_B);
nearest_lat = lat_A(IDX_lat);
nearest_lon = lon_A(IDX_lon);