Superimposing of the boundaries of world countries on a map

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

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

I tinkered a bit and it looks like you should use lat/lon limits similar to the values below. But you should not use my values--use the actual pixel center locations of your data. Also, the hsv colormap is a bit garish. Are your data categorical or sequential? I used the brewermap function on the file exchange site instead of your hsv(4).
h1=imagesc(linspace(-180,180,144),linspace(-60,75,55),Var);
set(h1,'alphadata',~isnan(Var))
caxis([1 4])
colormap(brewermap(6,'BuGn'))
You can also easily change the background color to ocean blue with rgb.
set(gca,'color',rgb('ocean blue'))
Thanks alot, it worked, my data is categorical, do you know how can I assign a specific color to a number, I have 4 clusters, so it means that the numbers of my matrix are 1,2,3, and 4 (or NaN which are mainly ocean). For example how can I assign red color to number 2 and blue color to number 1. In addition how can I change the thickness of country borders?
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.
Thank you Chad, your answers helped me alot.

Sign in to comment.

More Answers (0)

Categories

Asked:

Sam
on 28 Sep 2015

Commented:

Sam
on 7 Oct 2015

Community Treasure Hunt

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

Start Hunting!