How to find the contigous coordinate points between two varaibles datasets and do regression

Folks
I have two data variable sets of different sizes, A (chlorophyll) is 4317x3 matrix of lat, lon, and con. data value and B(SST) is 5851x3 matrix, of same lat, lon, and conc. data value. I want to find the coordinates in A data set that are closest to those B.
Then based on the index locations of those coordinates in the B matrix, extract out the concentration values from that correspond to those coordinates so that I can plot A and B concentration data sets value against one another.
The difficult part is to sort the coordinate locations in the A matrix with those in the B matrix, I would like to find the closest possible coordinate locations between the 2 large marice data sets.
please find the attached link for 2 datsets files
I have used this code
F = scatteredInterpolant(B(:,1), B(:,2), (1:size(B,1)).', 'nearest');
A_is_nearest_idx = F( A(:,1:2) )
B_closest_to_A = B(A_is_nearest_idx, :)
I find error
kindly help to sort the variables which was of continuous in order for synchronize and interpolate.

 Accepted Answer

idx = knnsearch(A(:,1:2),B(:,1:2)) ;
B = B(idx,:) ;

8 Comments

While using the code above I found this error Index in position 2 exceeds array bounds (must not exceed 1).
kindly help
T1 = readtable('chlor.csv') ;
T2 = readtable('sst.csv') ;
idx = knnsearch([T2.(1) T2.(2)],[T1.(1) T1.(2)]) ;
T2 = T2(idx,:) ;
plot(T1.(1),T1.(2),'.r')
hold on
plot(T2.(1),T2.(2),'ob')
Your A and B should be the matrices which you said. It sseems you are taking different variables. I have given the code with csv files, check that.
Actually I need sorted chlor and sst concentration data value of same coordinates with same number of rows
to perfrom statistical analysis / regression by keeping chlor along y and sst along x axis
The attched data is time series or data at one time step? What data you have exactly? What regression you want? Spatial or temporal?
The attached chlor and SST is of extracted regional MODIS Aqua netcdf time series data
I need spatial regression for chlor concentration data in relationship to that of SST conc.

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Asked:

on 23 Nov 2021

Commented:

on 23 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!