File Exchange Pick of the Week

November 15th, 2007

Practical example: Algorithm development for making colormaps

In a recent post, I mentioned LazyWeb It worked better than I expected. Matt posted some code that I requested that will highlight a line when you click on it. This works exactly as hoped. Thanks Matt, your MATLAB T-shirt has been shipped to thank you for your effort.

Ned thought this was great, so he posted a request for some code that makes colormaps.

I took up the challenge, mostly so that I could record how I went about developing an algorithm.

I broke this into two videos:

In this first video you will see:

  • The colormaps that we are developing from a journal article
  • The colormap applied to a MATLAB figure
  • How to call the code to make the colormap
  • Explaining the structure of a colormap in MATLAB
  • Exploring colormaps in the colormap editor
  • Plotting a colormap to understand its structure
  • Creating the colormap creating subfunction
  • Testing the subfunction

Find the files here.
PodCast here

In this second video you will see:

  • We review the colormaps that are to be made.
  • Show the four expected calling syntaxes for the function
  • Show how to use VARARGIN to make deal with different numbers of input arguments
  • Show error catching
  • Show different branches of code to be followed based on inputs
  • Developing an algorithm with cell mode to test an algorithm
  • Testing
  • Documentation

Find the files here.
PodCast here

This code was written live, so mistakes were made along the way. This gives you a realistic view of how a MATLAB expert deals with the inevitable errors that occur while programming.

The file that got created is useful on its own, so I have posted it here

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

Practical example videos have been gathered here:
http://blogs.mathworks.com/pick/category/practical-example

6 Responses to “Practical example: Algorithm development for making colormaps”

  1. Dan Pace replied on :

    Hi Doug - thanks for the helpful video. I have a question. Is it possible to display two surface plots, with different colormaps, on the same axes? Thanks - Dan

  2. Doug replied on :

    Dan,

    The colormap is a property of the Figure, so all axes in a figure share it.

    Doug

  3. Amir replied on :

    Dan,
    Here is the solution -
    http://www.mathworks.com/support/tech-notes/1200/1215.html
    Amir

  4. Andy replied on :

    Hi Doug - Thank you for creating the very useful makeColorMap. My goal was to integrate this function into my plots that use contourcmap.m. However, I kept getting an error, ‘cmap string must contain a colormap function name’ since contourcmap only allows built in Matlab color maps. My way around this was to comment out lines 64-68 of contourcmap. Do you recommend this solution, and if not, what other methods could I try? Thanks!

  5. Doug replied on :

    Andy,

    What was the commands you were using? I just tried the example in CONTOURCMAP only I made a throw-away function JETT that just calls JET. This worked fine. Please send or post the code you used and we can figure this out.

    I suspect that my colormap function expects different inputs than CONTOURCMAP gives so things are not working. You will probably want to make a wrapper around my function that takes just a single number input (like JET and other colormap functions do) so that when CONTOURCMAP calls it it will behave like the others.

    Doug

  6. Kika replied on :

    THANK YOU!!
    I’ve been trying to change the colormap but I didn’t know what to do. It was driving me crazy!
    Thank you very much for the help

    Kika

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?
  • Doug: @Lucy I think this is what you seek to move a line with the mouse in MATLAB. http://blogs.math...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.