Case sensitive feature fails
Show older comments
version: MATLAB R2018a
surf(peaks)
>> colormap BlueDarkOrange18
Error using feval
Cannot find an exact (case-sensitive) match for 'bluedarkorange18'
The closest match is: BlueDarkOrange18 in /usr/local/MATLAB/R2018a/toolbox/matlab/ncl_rgb/BlueDarkOrange18.m
Error in colormap (line 91)
arg = feval(arg);
My question is that, what I typed is 'BlueDarkOrange18', the error hints translated it into 'bluedarkorange18', this operation doesn't make sense.
6 Comments
Joel Handy
on 29 Jul 2019
You can actually pop open the colormap function and take a look. The color map you input is indeed converted to all lower case, presumably for convenience since all of the built in, predefined maps are lower case.
Where did this BlueDarkOrange18 colormap come from? Did you make it or is it from an external source? I'm wondering if it comes from something written for an older version of matlab that was less case sensative.
You have two options as a workaround, You can change the BlueDarkOrange18 function to be all lower case, or you could create a custom colormap function.
fuchang wang
on 29 Jul 2019
Guillaume
on 29 Jul 2019
"I checked MATLAB/R2018a/toolbox/matlab/graph3d/colormap.m [...] I comment it out"
"I wrote a function /toolbox/matlab/[...]"
Neither of these are a good idea. You should leave files in matlabroot alone.
In particular, it's totally pointless to modify colormap. Only you will be able to use your toolbox properly, the users of your toolbox won't (unless they also modify their matlab installation, I assume many will refuse).
The simplest workaround is to rename your colormap file to lower case. And possibly submit a bug report to matlab complaining about the behaviour of colormap.
Joel Handy
on 29 Jul 2019
"In particular, it's totally pointless to modify colormap. Only you will be able to use your toolbox properly, the users of your toolbox won't (unless they also modify their matlab installation, I assume many will refuse)"
I wouldn't say its pointless, but it is a bad idea for the reasons cited as well as the fact that it may prevent you from using other people's toolboxes properly.
Changing "BlueDarkOrange18" to "bluedarkorange18" is indeed the best solution if that's viable. If there are factors that make changing the name difficult, a better solution to modifying files in matlabroot would be to make a new function "myColormap" which has your desired functionality. You can then use that function in your application, distribute it as needed, and not break a matlab installation.
Steven Lord
on 29 Jul 2019
There is another alternative than changing the case of the function that defines your new colormap, and that is to change how you call colormap. The colormap function can accept the name of a colormap or an M-by-3 matrix that defines the colormap. Instead of calling colormap like this:
colormap BlueDarkOrange18
call it like this:
colormap(BlueDarkOrange18)
To support this, the BlueDarkOrange function should handle being called with either 0 or 1 inputs. With 0 inputs, it should return a matrix with a number of rows equal to the number of rows in the current figure's Colormap or the number of rows in the default colormap if there is no figure open. See the block of code at the start of the parula function for an example of how to obtain this information. With 1 input, if that input is a nonnegative scalar integer value it should return a colormap with that many rows.
fuchang wang
on 30 Jul 2019
Answers (0)
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!