Filter löschen
Filter löschen

issue with colormap (colorcube)

9 Ansichten (letzte 30 Tage)
Turbulence Analysis
Turbulence Analysis am 22 Dez. 2022
Kommentiert: Stephen23 am 23 Jan. 2023
Hi,
I am using colorcube colormap on the matlab 2018 and 2022b versions. The issue is I am getting different color palette on the two versions.
Is there any way to solve this issue?

Antworten (2)

DGM
DGM am 23 Jan. 2023
From the R2019b release notes:
Predefined colormaps have 256 colors by default
Behavior change
The predefined colormaps, such as parula, jet, and winter, now have 256 colors by default. If you have code that depends on a predefined colormap having 64 colors, specify the number of colors when you set the colormap for the figure, axes, or chart. For example, colormap(parula(64)) sets the figure's colormap to the 64-color parula colormap. Alternatively, you can change the default colormap for all figures within your MATLAB session:
set(groot,'defaultFigureColormap',parula(64))
In fact, the map generation routine itself has not changed. The only thing that's changed is how the various colormap functions determine the map length to use when none is explicitly given. This does not affect cases where the colormap length is specified explicitly.
The RN implies that the legacy behavior can be recreated by specifying a map length of 64. While that might work to adapt code which has otherwise not changed, it's important to understand that the behavior didn't simply change from "always default to 64" to "always default to 256".
In either version, if there is an open figure with a colormap set, the behavior of functions like colorcube()/jet(), etc is to create a map that's the same length as whatever the current colormap is -- regardless of whatever the defaults are. If you aren't explicitly specifying the map length when you use the colormap generation tools, you have no reliable control over what size map you get. Your code is not merely dependent on the version, but whatever potentially unrelated code ran before it. Specify the map length.

Bjorn Gustavsson
Bjorn Gustavsson am 22 Dez. 2022
Check that/if/how the two m-files differ. If they differ, copy the one you like better to the other system into a directory you have at the top of the matlab-path. Since you have licenses for the two versions this should be fine (I have no idea about how restrictively and draconicaly the copyright-rules can be applied). Since a colormap-function is not too foundational I have a hard time imagining a scenario where this would break some other functionality in the system where you add the other colorcube function. I might even consider adapting the function-name to something like best_colorcube.m, just to avoid any shadowing.
Others might have more formal advice on the legalities and system interference.
HTH
  2 Kommentare
Bjorn Gustavsson
Bjorn Gustavsson am 23 Jan. 2023
Was this answer sufficient to solve your problem?
DGM
DGM am 23 Jan. 2023
I only have R2019b, but as far as I can tell, this won't work (if moving the legacy function to a newer version). The only changes to the file are in how the map length is fetched from gcf or from the 'defaultfigurecolormap' property of groot. If there is no open figure, then the map length will be 256 based on the new default. If there is an open figure and the map therein was set using the same defaults, then it will still be 256.
The simple fix is to specify the map length when calling colorcube() or any of the map generation functions.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by