Passing no of colours in colormap as a variable

6 次查看(过去 30 天)
Hi,
I am plotting several different contour plots in a code. The code for plotting them is below. My problem is that for publication purpose, I want to use 3500 colours instead of 500 (as shown below) since the figure then looks smooth. But obviously Matlab runs extremely slow on my Mac. I wanted to pass no. of colours as a variable and change it at one place. So that I don't need to change it at several places in the code. When I pass the variable e.g. noColors = 3500, Matlab complains at colormap jet() line saying it needs finite values. How to play around this problem?
contourf( a0Grid, omegaPGrid, log10(freqShift), 500, 'Edgecolor', 'none' )
colormap jet(500)
  4 个评论
Image Analyst
Image Analyst 2013-2-19
But colormap(jet(noColors)) does? I didn't know that there would be a difference between the function call method and the command line method of calling colormap. It would be interesting to know the reason for that. I know there is a difference for some functions, like those that take a filename such as load() or save().
Walter Roberson
Walter Roberson 2013-2-19
colormap jet(500)
is equivalent to
colormap('jet(500)')
which is not a documented facility. It happens to work because colormap() feval()'s its argument when its argument is a string, but the documentation doesn't say that. The one example uses the function form equivalent to
colormap(jet(500))
which calls jet(500) and returns that numeric array as the argument to colormap()

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-2-19
Try
colormap(jet(noColors))
  5 个评论
Walter Roberson
Walter Roberson 2013-2-20
When you have
A B(C)
then due to MATLAB's "command / function equivalence", what would be passed to the function "A" would be the string 'B(C)'. "A" would then be responsible for interpreting the string. It happens that colormap() processes received strings using feval() or eval() and so runs whatever code is there, but that is more of an exception.
For example,
cd hotpink(128)
is not going to call hotpink(128): instead it would try to cd to a directory literally named 'hotpink(128)' complete with the () in the name.
When you use
A(B(C))
instead, then B(C) is evaluated as an expression, and the result (whatever data type it happens to be) is passed into A.
Naveen
Naveen 2013-2-20
Thanks for the explanation! You're a great help here!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by