Comparing 2 matrix with different size

Hi there! I am starting with matlab and I am a mess now.. I have a matrix A (69497x3) with latitude, longitude and depth, like:
-20.32245 54.00025 -4852
-20.33474 54.02638 -4352
-20.34776 54.05798 -3127
...
and a matrix B (601x601) with depth values. (I know the coordinates, latitude from -17º to -23º South, and longitude from 54º to 60º East)
-4600 -4589 -4572 -4555...
-4592 -4579 -4563 -4546...
...
I would like to find the values of matrix A on matrix B and generate a vector with the difference of the values. the number of values on A is lower than on B so the result should only contain the difference if there value exist in both matrix.
Thanks in advanced!

2 Comments

Can you post the expected result for the example you posted?
supposing that the values posted fit the same coordinates, should be differences like
[4852-4600 4352-4592 ...]
so the vector would be v=[252 -240 ... ] containing each result
Basically I need it to calculate how good is matrix B (an interpolation) versus matrix A (direct measures) by some statistics.

Sign in to comment.

 Accepted Answer

lat = flip(linspace(-23,-17 ,601),2)';
lon = linspace(54,60,601)';
l2 = [lat,lon];
B1 = B(:);
[lo,ii] = ismember(A(:,1:2),l2,'rows'); % or ismembertol (with R2015a)
out = [A(lo,1:2), A(lo,3)-B1(ii(lo))];
or with griddedInterpolant
F = griddedInterpolant({lat,lon},B);
ab = F(A(:,1),A(:,2));
out = [A(:,1:2), A(:,3) - ab];

More Answers (0)

Community Treasure Hunt

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

Start Hunting!