필터 지우기
필터 지우기

Get Colormap Values Corresponding to Array Values

조회 수: 126 (최근 30일)
Hannah_Mad
Hannah_Mad 2021년 8월 13일
댓글: Hannah_Mad 2021년 8월 13일
Dear Matlab Community,
Currently I am trying to visualize neuroimaging data and have thus run into the following problem:
I have an array of 1990 values, which I want to plot in different colors on a continuous colorbar. So all I would require is the information on how I can get a matrix with RGB triplets corresponding to the data in my array. I have already tried the following:
c = jet(cvals)
Which yields in the following code:
Error using /
Matrix dimensions must agree.
Error in jet (line 23)
u = [(1:1:n)/n ones(1,n-1) (n:-1:1)/n]';
Any help would be greatly appreciated.
Thank you!
  댓글 수: 2
Yazan
Yazan 2021년 8월 13일
What version of Matlab do you have? When run on 2021a, no errors were received.
Hannah_Mad
Hannah_Mad 2021년 8월 13일
I run R2021 a

댓글을 달려면 로그인하십시오.

채택된 답변

Chunru
Chunru 2021년 8월 13일
% rand cvars
cvars = randi([10 450], [128, 1]);
% You need to specify the number of colors to represent these cvars
n = 512;
cmap = jet(n);
% cvars has a different range from cmap range (1:512), so you have to map
% it. (similar to imagesc)
cvars_map = (cvars - min(cvars))/(max(cvars)-min(cvars)) * (n-1) + 1;
% Now find the color of i-th cvars
i = 10;
cvars(i)
ans = 136
cvars_map(i) % mapped cvars
ans = 147
cmap(cvars_map(i), :) % corresponding color
ans = 1×3
0 0.6484 1.0000
  댓글 수: 3
Chunru
Chunru 2021년 8월 13일
cvars is considered continuous (the code above just use the min and max of cvars). This continous values are then divided into n intervals. Each interval is then mapped into 1 of the n colors.
If you only have 70 unique values, then they correspond to 70 unique colors (out of n=512) colors. Some other colors will not really used.
If you do want to have each unique value correspond to a color, it can be also down. But you need to specify which color map you want to use.
Hannah_Mad
Hannah_Mad 2021년 8월 13일
Thank you very much! It works. Just one last question: if I have outliers (i.e. values are between 1 - 35) and one value is much higher (i.e. 70) is there any way I can change the colormap's limits? I only found caxis, but I do not think that it'll do the job 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