MATLAB Answers

How to make 2-D plot some points with Latitude, Longitude and Third value in Matlab?

16 views (last 30 days)
Zahra Sdi
Zahra Sdi on 16 Apr 2016
Commented: Dinibel Perez on 16 Sep 2019
Hi All,
I have 3 vectors, v1=Latitude, v2=Longitude and v3=value (like deformation). I want to make a 2-D plot that shows each point with it's coordinate in lat and lon, and shows the third value as a colour for each point.
Could you please let me know what the best way is to do that?
Thanks, Zahra
  4 Comments

Sign in to comment.

Answers (2)


Alireza Alizadeh
Alireza Alizadeh on 14 Aug 2018
Edited: Alireza Alizadeh on 14 Aug 2018
First of all you need an origin for the locations. I assumed that the first point is located at (X,Y) = (0,0). Then, you need to obtain the distances and bearing angles of all points with respect to the the first point using the following functions:
if true
function bearing = Bearing_Angle(lat1, lon1, lat2, lon2)
% convert decimal degrees to radians
lon1 = deg2rad(lon1);
lat1 = deg2rad(lat1);
lon2 = deg2rad(lon2);
lat2 = deg2rad(lat2);
bearing = atan2(sin(lon2-lon1)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1));
bearing = rad2deg(bearing);
bearing = mod((bearing + 360),360);
end
end
if true
function meter = haversine(lat1, lon1, lat2, lon2)
% https://andrew.hedges.name/experiments/haversine/
% convert decimal degrees to radians
lon1 = deg2rad(lon1);
lat1 = deg2rad(lat1);
lon2 = deg2rad(lon2);
lat2 = deg2rad(lat2);
dlon = lon2 - lon1;
dlat = lat2 - lat1;
% haversine formula
a = sin(dlat/2)^2 + cos(lat1) * cos(lat2) * sin(dlon/2)^2;
c = 2 * asin(sqrt(a));
km = 6367 * c;
meter = km*1000;
ft = km*3280;
miles = ft/5280;
end
end
Now, you can try the following code to obtain 2D locations and plot the points:
if true
Locations_XY = zeros(N,2);
Locations_XY(1,:)= [0 0];
for n = 2 : N
theta_deg = Bearing_Ang(1,n);
theta = (2*pi*theta_deg)/360;
d = Dist(1,n);
Locations_XY(n,:)= [d*sin(theta) d*cos(theta)];
end
figure
hold on
box on
for n = 1 : N
plot(Locations_XY(n,1),Locations_XY(n,2),'sb','markersize',40,'markerfacecolor','c');
text(Locations_XY(n,1),Locations_XY(n,2), num2str(n),'FontSize',12,'HorizontalAlignment','center');
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by