Black horizontal patches in the plot
I am plottting a simple sst difference plot. My lon data is in the range -180 to 180. I have converted it to 0 to 360. After plotting I am geeting these black patches (attached).
clear
clc
% Define the file paths for WeakTEJYears
WeakTEJYears = {
‘F:SST_MA1979.nc’
‘F:SST_MA1983.nc’
‘F:SST_MA1987.nc’
‘F:SST_MA1997.nc’
‘F:SST_MA2002.nc’
‘F:SST_MA2015.nc’
‘F:SST_MA2023.nc’
};
% Define the file paths for StrongTEJYears
StrongTEJYears = {
‘F:SST_MA1985.nc’
‘F:SST_MA1988.nc’
‘F:SST_MA1999.nc’
‘F:SST_MA2009.nc’
‘F:SST_MA2013.nc’
};
% Initialize variables to store the sum of SST data
sst_sum_weak = 0;
sst_sum_strong = 0;
num_weak_files = length(WeakTEJYears);
num_strong_files = length(StrongTEJYears);
lat_min = -25;
lat_max = 70;
lon_min = 0;
lon_max = 360;
for i = 1:num_weak_files
ncfile = WeakTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :); % Re-sort SST data according to longitude sorting
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_weak = sst_sum_weak + mean(sst_region, 3); % Mean over time
end
for i = 1:num_strong_files
ncfile = StrongTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :);
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_strong = sst_sum_strong + mean(sst_region, 3); % Mean over time
end
sst_avg_weak = sst_sum_weak / num_weak_files;
sst_avg_strong = sst_sum_strong / num_strong_files;
sst_diff = sst_avg_strong – sst_avg_weak;
figure;
[lon_mesh, lat_mesh] = meshgrid(longitude(lon_idx), latitude(lat_idx));
contourf(lon_mesh, lat_mesh, sst_diff’, 20, ‘EdgeColor’, ‘none’);
colormap jet;
colorbar;
caxis([-2, 2]);
c.Label.String = ‘Temperature (K)’;
c.Label.FontSize = 18;
c.Label.FontWeight = ‘bold’;
coast = load(‘coastlines’);
coastlon = coast.coastlon;
coastlat = coast.coastlat;
coastlon(coastlon < 0) = coastlon(coastlon < 0) + 360;
hold on;
plot(coastlon, coastlat, ‘k’, ‘LineWidth’, 1.5);
xlim([lon_min, lon_max]);
ylim([lat_min, lat_max]);
title(‘Difference: Strong – Weak TEJ Average SST’, ‘FontSize’, 14);I am plottting a simple sst difference plot. My lon data is in the range -180 to 180. I have converted it to 0 to 360. After plotting I am geeting these black patches (attached).
clear
clc
% Define the file paths for WeakTEJYears
WeakTEJYears = {
‘F:SST_MA1979.nc’
‘F:SST_MA1983.nc’
‘F:SST_MA1987.nc’
‘F:SST_MA1997.nc’
‘F:SST_MA2002.nc’
‘F:SST_MA2015.nc’
‘F:SST_MA2023.nc’
};
% Define the file paths for StrongTEJYears
StrongTEJYears = {
‘F:SST_MA1985.nc’
‘F:SST_MA1988.nc’
‘F:SST_MA1999.nc’
‘F:SST_MA2009.nc’
‘F:SST_MA2013.nc’
};
% Initialize variables to store the sum of SST data
sst_sum_weak = 0;
sst_sum_strong = 0;
num_weak_files = length(WeakTEJYears);
num_strong_files = length(StrongTEJYears);
lat_min = -25;
lat_max = 70;
lon_min = 0;
lon_max = 360;
for i = 1:num_weak_files
ncfile = WeakTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :); % Re-sort SST data according to longitude sorting
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_weak = sst_sum_weak + mean(sst_region, 3); % Mean over time
end
for i = 1:num_strong_files
ncfile = StrongTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :);
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_strong = sst_sum_strong + mean(sst_region, 3); % Mean over time
end
sst_avg_weak = sst_sum_weak / num_weak_files;
sst_avg_strong = sst_sum_strong / num_strong_files;
sst_diff = sst_avg_strong – sst_avg_weak;
figure;
[lon_mesh, lat_mesh] = meshgrid(longitude(lon_idx), latitude(lat_idx));
contourf(lon_mesh, lat_mesh, sst_diff’, 20, ‘EdgeColor’, ‘none’);
colormap jet;
colorbar;
caxis([-2, 2]);
c.Label.String = ‘Temperature (K)’;
c.Label.FontSize = 18;
c.Label.FontWeight = ‘bold’;
coast = load(‘coastlines’);
coastlon = coast.coastlon;
coastlat = coast.coastlat;
coastlon(coastlon < 0) = coastlon(coastlon < 0) + 360;
hold on;
plot(coastlon, coastlat, ‘k’, ‘LineWidth’, 1.5);
xlim([lon_min, lon_max]);
ylim([lat_min, lat_max]);
title(‘Difference: Strong – Weak TEJ Average SST’, ‘FontSize’, 14); I am plottting a simple sst difference plot. My lon data is in the range -180 to 180. I have converted it to 0 to 360. After plotting I am geeting these black patches (attached).
clear
clc
% Define the file paths for WeakTEJYears
WeakTEJYears = {
‘F:SST_MA1979.nc’
‘F:SST_MA1983.nc’
‘F:SST_MA1987.nc’
‘F:SST_MA1997.nc’
‘F:SST_MA2002.nc’
‘F:SST_MA2015.nc’
‘F:SST_MA2023.nc’
};
% Define the file paths for StrongTEJYears
StrongTEJYears = {
‘F:SST_MA1985.nc’
‘F:SST_MA1988.nc’
‘F:SST_MA1999.nc’
‘F:SST_MA2009.nc’
‘F:SST_MA2013.nc’
};
% Initialize variables to store the sum of SST data
sst_sum_weak = 0;
sst_sum_strong = 0;
num_weak_files = length(WeakTEJYears);
num_strong_files = length(StrongTEJYears);
lat_min = -25;
lat_max = 70;
lon_min = 0;
lon_max = 360;
for i = 1:num_weak_files
ncfile = WeakTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :); % Re-sort SST data according to longitude sorting
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_weak = sst_sum_weak + mean(sst_region, 3); % Mean over time
end
for i = 1:num_strong_files
ncfile = StrongTEJYears{i};
latitude = ncread(ncfile, ‘latitude’);
longitude = ncread(ncfile, ‘longitude’);
longitude(longitude < 0) = longitude(longitude < 0) + 360;
[longitude, sort_idx] = sort(longitude);
sst = ncread(ncfile, ‘sst’);
sst_sorted = sst(sort_idx, :, :);
lat_idx = find(latitude >= lat_min & latitude <= lat_max);
lon_idx = find(longitude >= lon_min & longitude <= lon_max);
sst_region = sst_sorted(lon_idx, lat_idx, :);
sst_sum_strong = sst_sum_strong + mean(sst_region, 3); % Mean over time
end
sst_avg_weak = sst_sum_weak / num_weak_files;
sst_avg_strong = sst_sum_strong / num_strong_files;
sst_diff = sst_avg_strong – sst_avg_weak;
figure;
[lon_mesh, lat_mesh] = meshgrid(longitude(lon_idx), latitude(lat_idx));
contourf(lon_mesh, lat_mesh, sst_diff’, 20, ‘EdgeColor’, ‘none’);
colormap jet;
colorbar;
caxis([-2, 2]);
c.Label.String = ‘Temperature (K)’;
c.Label.FontSize = 18;
c.Label.FontWeight = ‘bold’;
coast = load(‘coastlines’);
coastlon = coast.coastlon;
coastlat = coast.coastlat;
coastlon(coastlon < 0) = coastlon(coastlon < 0) + 360;
hold on;
plot(coastlon, coastlat, ‘k’, ‘LineWidth’, 1.5);
xlim([lon_min, lon_max]);
ylim([lat_min, lat_max]);
title(‘Difference: Strong – Weak TEJ Average SST’, ‘FontSize’, 14); spatial map, image analysis, matrix manipulation MATLAB Answers — New Questions