필터 지우기
필터 지우기

Passing no of colours in colormap as a variable

조회 수: 2 (최근 30일)
Naveen
Naveen 2013년 2월 19일
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