how define colormap for range of value of z data
Mostra commenti meno recenti
i want create colormap for z value by following range : 100-1200 blue 1200-1300 red 1300-1400 yellow 1400 to up green, please help me to create this colormap. thanks.
Risposte (1)
That is not how colormaps work. In MATLAB colormaps are just a list (a matrix) of colors, they do not include any mapping information, such as what you are requesting. If you wish to create a mapping of those colors to a particular range of values, then you have to consider this yourself when you are platting that data. This means that what and how you are plotting is critical to know how to get the colors that you want. Because you did not tell us anything about what you are plotting, nor how, it is hard to give any advice other than read the documentation for the functions that you are using.
For functions that use them, the colormap is applied evenly over the entire range of the plotted data. This means that it is possible to create a colormap where particular colors correspond to particular values in the plotted data, but again this requires knowing something about the plotted values, how they are plotted, and then adjusting/creating a colormap to suit this.
Here is an example colormap, note how it is simply a collection of RGB triples, and that it does not contain any mapping information (like you requested):
>> cool(5)
ans =
0 1 1
0.25 0.75 1
0.5 0.5 1
0.75 0.25 1
1 0 1
To map the colormap to a particular set of data, you need to show us exactly how you are plotting that data, and what the range of your data is.
2 Commenti
jamshid zarinmehr
il 13 Giu 2016
Modificato: Stephen23
il 13 Giu 2016
As I already wrote in my answer, you should read the meshz documentation: it explains how to provide an optional fourth argument C that controls the color.
Here is a simple example of how it works:
% fake data:
[X,Y] = ndgrid(0:9);
Z = X+Y;
% fit data into bins:
B = [0,2,5,10,20]; % bin edges
[V,C] = histc(Z,B);
% define colormap with four colors:
map = [0,0,1;1,0,0;1,1,0;0,1,0]; % blue;red;yellow;green
% plot:
meshz(X,Y,Z,C)
colormap(map)
Note that the colormap map has only four rows / colors, and the variable C is an index with values between one and four. Thus the values of C correspond to the colors used. It looks like this:

Categorie
Scopri di più su Purple in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!