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 ?

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

Can you attach the 2 xlsx files and 1 csv file you are using?
Hi @Voss thanks for your attention but i can not share file or datas. Kinda forbidden lets say. But i rearrenge the code and maybe you can say how can i improve the new version of code. I filtered the code via Gaussian filter to reach smoother image. I know it is hard to estimate without the datas but thanks in advance !
% Load latitude and longitude data
latTable = readtable('C:\Users\gozde\Desktop\sat_lat.xlsx');
lat = latTable.Column2; % Latitude column name is Column2
longTable = readtable('C:\Users\gozde\Desktop\sat_long.xlsx');
long = longTable.Column3; % Longitude column name is Column3
% magnetometer 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 magnetometer
MAG = zeros(size(m, 1), 1);
for i = 1:size(m, 1)
MAG(i) = norm(m(i, :));
end
% Creating regularly spaced grid for interpolation
xq = linspace(min(lat), max(lat), 50);
yq = linspace(min(long), max(long), 50);
[Xq, Yq] = meshgrid(xq, yq);
% Interpolate magnetometer data to the regular grid
Zq = griddata(lat, long, MAG, Xq, Yq, 'cubic'); % You can adjust the smoothing method ('cubic' or 'linear')
% Smooth the data using a Gaussian filter
sigma = 1; % Adjust the smoothing factor as needed
Zq_smoothed = imgaussfilt(Zq, sigma);
% Create a contour plot
figure;
contourf(Xq, Yq, Zq_smoothed, 20, 'LineColor', 'k'); % Adjust the number of contour levels as needed
colorbar;
xlabel('Latitude');
ylabel('Longitude');
title('Magnetometer 2D Contour Map with Gaussian Smoothing');
colormap('jet');
Also It doesn't have to look exactly like the first figure. Something like this works for me. (this is the image my code should look like)

Sign in to comment.

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

Products

Release

R2022a

Asked:

on 5 Sep 2023

Edited:

on 6 Sep 2023

Community Treasure Hunt

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

Start Hunting!