I have a latitude longitude infos and a certain data. I am tryna do a 2D contour earth map using all of these. But result not right why ?
Show older comments
Here is my code. But the result map is not right. How can i visualize?
% Load latitude and longitude data
latTable = readtable('C:\Users\gozde\Desktop\sat_lat.xlsx');
lat = latTable.Column2;
longTable = readtable('C:\Users\gozde\Desktop\sat_long.xlsx');
long = longTable.Column3;
% Load your data from the CSV file
mTable = readtable('C:\Users\gozde\Desktop\genel unzip\GENEL\GENELims\BUS_DATA_COMBINED.csv', 'Range', 'L2:N17026');
m = mTable{:,:};
% Calculate the magnitude of vectors
MAG = zeros(size(m, 1), 1);
for i = 1:size(m, 1)
MAG(i) = norm(m(i, :));
end
% Create a 2D map of the Earth
figure;
worldmap world;
load coastlines; % Load coastlines for reference
geoshow(coastlat, coastlon, 'DisplayType', 'line', 'Color', 'black');
% Convert latitude and longitude to double arrays
lat = double(lat);
long = double(long);
% Create regularly spaced x and y values
xq = linspace(min(lat), max(lat), 50);
yq = linspace(min(long), max(long), 50);
[Xq, Yq] = meshgrid(xq, yq);
% Use the scattered interpolant to compute the grid of Z values
F = scatteredInterpolant(lat, long, MAG, 'linear', 'linear');
Zq = F(Xq, Yq);
% Create the contour plot
contourm(Xq, Yq, Zq, 'LineColor', 'black'); % Adjust LineColor as needed
colorbar;
framem on;
gridm on;
mlabel on;
plabel on;
colormap('jet');
Here it is my result.

And i want a result like this

3 Comments
Voss
on 5 Sep 2023
Can you attach the 2 xlsx files and 1 csv file you are using?
Gözde
on 5 Sep 2023
Edited: Walter Roberson
on 6 Sep 2023
Answers (1)
% some fake data:
N = 17025;
lat = rand(N,1)*180-90;
long = rand(N,1)*360-180;
m = rand(N,4);
% Calculate the magnitude of magnetometer
MAG = zeros(size(m, 1), 1);
for i = 1:size(m, 1)
MAG(i) = norm(m(i, :));
end
% Create a 2D map of the Earth
figure;
worldmap world;
% Create regularly spaced x and y values
xq = linspace(min(lat), max(lat), 50);
yq = linspace(min(long), max(long), 50);
[Xq, Yq] = meshgrid(xq, yq);
% Use the scattered interpolant to compute the grid of Z values
F = scatteredInterpolant(lat, long, MAG, 'linear', 'linear');
Zq = F(Xq, Yq);
% Create the contour plot
contourfm(Xq, Yq, Zq, 'LineColor', 'none');
load coastlines; % Load coastlines for reference
geoshow(coastlat, coastlon, 'DisplayType', 'line', 'Color', 'black');
colorbar;
framem on;
gridm on;
mlabel on;
plabel on;
colormap('jet');
Categories
Find more on Geographic Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

