Code covered by the BSD License  

Highlights from
Color Palette Tables (.cpt) for Matlab

5.0

5.0 | 2 ratings Rate this file 38 Downloads (last 30 days) File Size: 16.75 KB File ID: #28943
image thumbnail

Color Palette Tables (.cpt) for Matlab

by Kelly Kearney

 

04 Oct 2010 (Updated 12 Apr 2011)

Create and apply GMT-style colormaps in Matlab

| Watch this File

File Information
Description

This function creates and applies a colormap defined in a color palette table (.cpt) file. Color palette tables are used to define colormaps in the Generic Mapping Tools package (http://gmt.soest.hawaii.edu/). These files provide more flexible colormapping than Matlab's default schemes, including both discrete and continuous gradients, as well as easier direct color mapping.

For a complete description of the color palette table format, see the GMT documentation.

This package includes 20 standard GMT colormaps; please see the header of each file for copyright information. Many more color tables are available on the cpt-city website (http://soliton.vm.bytemark.co.uk/pub/cpt-city/index.html).

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
11 Oct 2010 Marios Karaoulis

Hi. Very nice package. Is it possible to use the inverse colormap of GMT_seis.cpt?

11 Oct 2010 Kelly Kearney

Marios,

If by the inverse colormap, you mean you want to flip the direction of the colors, then yes, use the 'flip' option:

cptcmap('GMT_seis', 'flip', true)

-Kelly

26 Mar 2011 Felipe G. Nievinski

Great idea, always wanted to make my matlab maps look like gmt's. Also thanks for pointing out to cpt-city, it's a great collection.

You might want to use the acknowledgement field in the FEX form, so that your submission is back-linked from related entries, e.g., 28982 and the ones linked from there.

03 Apr 2011 Felipe G. Nievinski

You might want to replace l.83:

  cptpath = './cptfiles';

with:

  cptpath = fullfile(fileparts(which('cptcmap')), 'cptfiles');

That way the source code needs not be modified when first downloading the package or later when moving the routine files around.

I was having problems trying

  cptcmap('elevation')

where elevation.cpt was downloaded from cpt-city and placed in the cptpath; it turns out that l.98,

  if exist(varargin{1}, 'file') % full filename and path given

would find this other file instead:

  which elevation
  C:\Program Files\MATLAB\R2009b\toolbox\map\map\elevation.m

You might want to replace the block l.98-111 with the following (minimally modified):

  if ~strcmp(varargin{1}(end-3:end), '.cpt') % without extension
      varargin{1} = [varargin{1} '.cpt'];
  end
  if exist(varargin{1}, 'file') % full filename and path given
      filename = varargin{1};
  else % only file name given
      filename = fullfile(cptpath, varargin{1});
      if ~exist(filename, 'file')
          error('Specified .cpt file not found');
      end
  end

Finally, not sure why the __MACOSX subdirectory is being distributed.

03 Apr 2011 Felipe G. Nievinski

Another one, trying

  cptcmap('sst')

Just had to replace

  if ~strcmp(varargin{1}(end-3:end), '.cpt') % without extension

for:

if (numel(varargin{1}) <= 4) || ~strcmp(varargin{1}(minend-3:end), '.cpt') % without extension

03 Apr 2011 Felipe G. Nievinski

Another one, trying

  cptcmap('sst')

Just had to replace

  if ~strcmp(varargin{1}(end-3:end), '.cpt') % without extension

for:

if (numel(varargin{1}) <= 4) || ~strcmp(varargin{1}(end-3:end), '.cpt') % without extension

27 Mar 2012 camilo melo

hi, does this function works for MATLAB R2011b?? i tried to use it but got this error message Index exceeds matrix dimensions.

Error in cptcmap (line 123)
[blah, blah, ext] = fileparts(varargin{1});

28 Mar 2012 Kelly Kearney

@camilo melo,

I don't have R20011b, so I can't test it, but I can't think of any reason it wouldn't work in that version. Based on the error message you mention, my guess is you tried to call the function without any input arguments; it needs at least one (the name of the colormap).

Please login to add a comment or rating.
Updates
12 Apr 2011

-bug fixes where some input filenames were misinterpreted (thanks to Felipe)
-colormap display option no longer relies on external functions, has cleaner display, and renders more quickly

Tag Activity for this File
Tag Applied By Date/Time
color palette table Kelly Kearney 05 Oct 2010 11:28:28
colormap Kelly Kearney 05 Oct 2010 11:28:29
gradient Kelly Kearney 05 Oct 2010 11:28:29
color Felipe G. Nievinski 28 Mar 2011 16:45:04
gradient Andrew 15 May 2012 17:03:45

Contact us at files@mathworks.com