- You need to have SAU_adm0.shx in your Desktop\March directory.
- You are using a version of MATLAB older than R2016b, but this code was written for R2016b or later. To offer you the proper fix for the string() issue, we need to know which release you are using
- The code was written for R2014b or later in the way it uses round(). We need to know what release you are using.
help Surface Temperature Contour Plot
1 view (last 30 days)
Show older comments
Hi all, could anyone help me with this code .it shows the following errors
Also, when a plot my Results Gives results on the contrary
For example, the data of the end of the Gulf shows high temperatures compared to the end of the open my plot shows the opposite where the blue color shows lower temperatures while must higher .
%%========================================================
Warning: Failed to open file C:\Users\DELLpower\Desktop\march\SAU_adm0.shx or file
C:\Users\DELLpower\Desktop\march\SAU_adm0.SHX. Will build index from SHP file.
> In mapformats\private\openShapeFiles>openSHX at 107
In mapformats\private\openShapeFiles at 26
In shaperead at 206
In readMapData>readFromShapeFile at 134
In readMapData at 32
In map\private\importFromFileAndSetDataArgs at 27
In geoshow at 262
Warning: Failed to open file C:\Users\DELLpower\Desktop\march\SAU_adm0.shx or file
C:\Users\DELLpower\Desktop\march\SAU_adm0.SHX. Depending on DBF file to get number of records.
> In mapformats\private\openShapeFiles>openSHX at 109
In mapformats\private\openShapeFiles at 26
In shapeinfo at 72
In readMapData>readFromShapeFile at 136
In readMapData at 32
In map\private\importFromFileAndSetDataArgs at 27
In geoshow at 262
>>
Warning: string is obsolete and will be discontinued.
Use char instead.
Warning: Failed to open file C:\Users\DELLpower\Desktop\march\SAU_adm0.shx or file
C:\Users\DELLpower\Desktop\march\SAU_adm0.SHX. Will build index from SHP file.
> In mapformats\private\openShapeFiles>openSHX at 107
In mapformats\private\openShapeFiles at 26
In shaperead at 206
Warning: Failed to open file C:\Users\DELLpower\Desktop\march\SAU_adm0.dbf or file
C:\Users\DELLpower\Desktop\march\SAU_adm0.DBF. Shape output structure will have no attribute fields.
> In mapformats\private\openShapeFiles>openDBF at 122
In mapformats\private\openShapeFiles at 27
In shaperead at 206
Error using round
Too many input arguments.
%==========================================================================
% Surface Temperature Contour Plot
% Read Excel Sheet Data
close all;clear;clc
[rawDataNum,rawDataStr] = xlsread('Summerand Spring.xlsx','Sheet1','A1:J27');
% Extract Required Data from Raw Data
longitudes = rawDataNum(1,1:end);
latitudes = rawDataNum(2,1:end);
sstAll = rawDataNum(4:end,1:end);
sstAvg = mean(sstAll);
figure(1)
% Limit geograpical co-ordinates to required area
worldmap([21.7 21.78],[39.07 39.15])
% Display land area limited to bay region
LandArea = geoshow('SAU_adm0.shp');
% Plot individual markers on the map data
% Initialize a Jet Colormap with 8 colors
jetColorMap = jet(length(sstAvg));
for i = 1:length(sstAvg)
% Get the color for this subject from the jet colormap.
markerColour = jetColorMap(i,:);
hold on
plotm(latitudes(i),longitudes(i),sstAvg(i),'Marker','o','MarkerSize',10,'MarkerFaceColor',markerColour)
textm(latitudes(i) ,longitudes(i) + 0.001,num2str(sstAvg(i)),'Color','m')
end
% Display colorbar.
colormap(jetColorMap);
colorbar('YTickLabel',string(linspace(min(sstAvg),max(sstAvg),5)))
title('Geomap of Surface Temperature')
% Load landfile to an array
shp_res = shaperead('SAU_adm0.shp');
x1 = round(shp_res.BoundingBox(1,1))-1;
x2 = round(shp_res.BoundingBox(2,1))+1;
y1 = round(shp_res.BoundingBox(1,2))-1;
y2 = round(shp_res.BoundingBox(2,2))+1;
[lonS, latS]= meshgrid(x1:0.01:x2,y1:0.01:y2);
lon1(1,:) = lonS(1,:); lat1(1,:) = latS(:,1);
x4 = length(lon1); y4 = length(lat1);
Z = randn(y4,x4);
% create the mat file
R = makerefmat('RasterSize',size(Z'),'Lonlim',[39.07 39.15],'Latlim',[21.7 21.78]);
mat_data = vec2mtx(shp_res.Y,shp_res.X,Z',R,'filled');
mat_data = imrotate(flip(mat_data',2),180);
mat_data = mat_data'; %first generate the transpose
mat_data(end:-1:1)= mat_data; %then flip it
mat_data = mat_data - min(mat_data(:));
mat_data = mat_data / max(mat_data(:));
[lonS, latS]= meshgrid(linspace(39.07,39.15,size(mat_data,1)),linspace(21.7,21.78,size(mat_data,2)));
% % geoshow(latS',lonS',flip(mat_data,1));
% Interpolate data to create a mesh surface
vq = griddata(latitudes,longitudes,sstAvg,latS,lonS,'natural');
vq = imrotate(vq,-90);
cmin = nanmin(vq(:));
cmax = nanmax(vq(:));
vq(isnan(vq)) = 0;
% Dilation to create the gradient
se = strel('disk',300);
vq = imdilate(vq,se);
overlap_mat = ones(size(vq,1),size(vq,2));
overlap_mat(vq == 0) = 0;
landfilled = vq .* mat_data;
overlap_mat = ~(overlap_mat & mat_data) & mat_data;
% landfilled(overlap_mat == 1) = cmax + cmax * 0.001;
landfilled(overlap_mat == 1) = 500;
% landfilled(landfilled == 0) = cmin - cmin * 0.001;
landfilled(landfilled == 0) = 0;
% Display final Image
figure;imagesc(landfilled);
jetColorMap2 = jet(200);
jetColorMap2(1,:) = [0.9 0.9 0.9];
% jetColorMap2(end,:) = [0.7 0.7 0.7];
colormap(jetColorMap2);
colorbar
caxis([cmin cmax]);
xlabel('Longitudes')
xticklabels(round(linspace(min(longitudes),max(longitudes),9),2))
ylabel('Latitudes')
yticklabels(round(linspace(min(latitudes),max(latitudes),5),2))
title('Geomap of Surface Temperature')
0 Comments
Answers (2)
Walter Roberson
on 13 Apr 2019
2 Comments
Walter Roberson
on 14 Apr 2019
You will need to find SAU_adm0.shx yourself, possibly from https://data.world/ocha-romena/41ce9023-1d21-4549-a485-94316200aba0
For your code, change
colorbar('YTickLabel',string(linspace(min(sstAvg),max(sstAvg),5)))
to
colorbar('YTickLabel', linspace(min(sstAvg),max(sstAvg),5))
Change
xticklabels(round(linspace(min(longitudes),max(longitudes),9),2))
ylabel('Latitudes')
yticklabels(round(linspace(min(latitudes),max(latitudes),5),2))
to
xt = linspace(min(longitudes), max(longutides), 9);
xtc = cellstr( num2str(xt(:), '%.2f') );
yt = linspace(min(latitudes), max(latitudes), 5);
ytc = cellstr( num2str(yt(:), '%.2f') );
ylabel('Latitudes')
set(gca, 'XTickLabels', xtc, 'YTickLabels', ytc)
b.m.n n
on 14 Apr 2019
2 Comments
Walter Roberson
on 14 Apr 2019
The first plot with the circle markers makes no attempt to color by temperature. It creates a jet colormap and then colors in index order. We have no reason to expect that sstAvg will happen to be sorted in increasing order.
See Also
Categories
Find more on Orange 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!