Problem with colormap command using hsv

1 次查看(过去 30 天)
Hi There. I'm still a relatively elementary-level Matlab programmer, and I've come across a problem with a figure I'm making for my thesis. The plot is fairly complex, but the problem really shouldn't be. I have a range of data, and I tailor the colors of plot to the range that I compute (which can change each time I run my code). At the moment the range is 94 units, so I first tell my plot the color axis: caxis([MinValue MaxValue]), and then define the colormap as colormap(hsv(Range)) where Range is (MaxValue-MinValue)+1. In my experience this shouldn't be a problem, but the colormap command, which is essentially the same here as saying "make me an hsv matrix that is 94 entries down and three across" keeps spitting back this error:
Error using ==> set All colormap intensities must be between 0 and 1
Error in ==> colormap at 95 set(figH, 'Colormap', arg);
The worst part is that this error usually happens, but in some small number of cases, it doesn't, and the plot comes up just fine. I can't find any reason for this inconsistency.
I do plot a lot of other figures in my code, and I'm wondering if somehow I'm overloading the colormap command, but every time I've gone into colormap and set a setpoint at line 95, I've checked the arg and arg1 matrices it uses and none have values that are below 0 or above 1. It's a mystery to me, and I'm inclined to think it's a bug in hsv unless I'm really screwing up the use of the colormap command in the first place. I will say I've successfully used this command almost exactly as this one appears many times in the past without problem...
Any help you can give is greatly appreciated.
Best, Jonathan
  1 个评论
Jonathan
Jonathan 2013-8-16
I should mention that I don't have the same issue using colormap(jet(Range)), but my data is subtle enough to need the extra colors that hsv provides.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-8-16
At the command line give the command
format long g
cmap = hsv(Range);
size(cmap)
min(cmap(:))
max(cmap(:)) - 1
Do this checking just in case the values are near but not exactly what you need.
  5 个评论
Image Analyst
Image Analyst 2013-8-19
编辑:Image Analyst 2013-8-19
What did Walter's code spit out for max and min in the situations where it bombed? I find it hard to believe that in the case where it bombed it said a min of 0 and a max of 1 (or anything inside that range). If it did, then it wouldn't/shouldn't have bombed.
Jonathan
Jonathan 2013-8-22
I've sorted out the issue, and it reveals that my knowledge of Matlab data types is still progressing... For some reason the data type was single not double (I'll have to look up why this is an issue), and apparently hsv or colormap will not always accept a single input, though this has never been an issue for jet or other color schemes I've used. So, I've just instructed it to take colormap(hsv(double(Range))); Works fine every time I've tried since, so I believe this was the root of the problem. Thanks to all for the help. If I understand the format here, I'm going to accept my own answer in case anyone else comes across this issue. (Though this seems a bit odd)

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by