Superimposing of the boundaries of world countries on a map

5 views (last 30 days)
Hi I have a matrix (the name of matrix is "matrix_of_cluster") with 55 rows and 144 columns,each guy of this matrix is a number (or NaN) which represents a grid of earth (each grid is 2.5 degree*2.5 degree), this matrix covers latitude: 60S-77.5N and longitude: 180W-180E, I mapped this matrix using the following code. I want to put the boundaries of countries on this map. I tried to use worldmap and geoshow functions, but it did not work. How can I do this? The necessary files have been attached.
Var=matrix_of_cluster;
h1=imagesc(Var);
set(h1,'alphadata',~isnan(Var))
colormap hsv(4)
set(gca,'YDir','normal')
colorbar('location','Eastoutside')

Accepted Answer

Chad Greene
Chad Greene on 1 Oct 2015
Hi Ehsan,
You can use a function I wrote for this called borders. But your lat,lon values are not correct. You'll need to explicitly state those values when you plot with imagesc.
  5 Comments
Chad Greene
Chad Greene on 7 Oct 2015
You can assign colors in any order you want by specifying their rgb values. For example,
colormap([1 0 0;0 1 0])
creates two-color colormap made up of only red and green. For prettier colormaps I recommend brewermap on file exchange, which could be used with the syntax
colormap(brewermap(4,'Set1'))
to get a nice 4-color colormap. Another option is to use a fancy color picking website like IWantHue and convert from hex values to rgb with hex2rgb if necessary.
% define some random data:
A = randi(4,10);
% plot gridded data:
imagesc(A)
% define a colormap:
colormap(hex2rgb({'#01A9EF','#B7790B','#67DF91','#82167E'}))
% initialize a colorbar:
cb = colorbar;
% set color axis limits:
caxis([0.5 4.5])
% label categorical data:
set(cb,'ytick',1:4,...
'yticklabel',{'data 1';'data 2';'data 3';'data 4'})
To change border line width, just use ...,'LineWidth',4) or whatever value thickness you want. Type
showdemo borders_documentation
to see a few examples of that.

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps 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!