Created
January 16, 2022 08:18
-
-
Save Umair444/55d73a67001965bcc2a21ecbda561cde to your computer and use it in GitHub Desktop.
Spatial Joining MATLAB - Shift Attributes using spatial data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% FORMAT: | |
% DATA1 = [ID1 Lat Lon] | |
% DATA2 = [ID2 data Lat Lon] | |
%% Remove nan Before | |
DATA1(isnan(DATA1.Lat), :) = []; | |
DATA2(isnan(DATA2.Lat), :) = []; | |
%% Calculate Dist | |
dist = zeros(length(DATA2.ID2), length(DATA1.ID1)); | |
for i = 1:length(DATA1.Lat) | |
for j = 1:length(DATA2.Lat) | |
dist(j, i) = distance(DATA1.Lat(i), DATA1.Lon(i), DATA2.Lat(j), DATA2.Lon(j)); % Need mapping toolbox | |
end | |
end | |
% dist = dist'; | |
%% Remove NAN Rows Column | |
% dist = dist(any(~isnan(dist),2),:); | |
% dist = dist(:,any(~isnan(dist))); | |
%% Calculate Min | |
m = zeros(1,size(dist,2)); | |
idx = zeros(1,size(dist,2)); | |
for k = 1:size(dist,2) | |
[m(k), idx(k)] = min(dist((dist(:, k) > 0), k), [], 'omitnan'); | |
end | |
%% Display | |
result = [DATA2.ID2(idx) DATA1.ID1 DATA2.data(idx) m']; | |
histfit(m); | |
disp(mean(m)); | |
%% Histo | |
figure, | |
[a,b] = groupcounts(result(:,2)+"/"+result(:,3)); | |
bar(a); | |
xticks(1:68); | |
xticklabels(b); |
Author
Umair444
commented
Jan 16, 2022
- Join two datasets - and shift attributes based on spatial charaterstics of data.
- Visualize the distance distribution (normal)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment