필터 지우기
필터 지우기

set colormap values to an array

조회 수: 32 (최근 30일)
bsriv
bsriv 2022년 11월 15일
댓글: bsriv 2022년 11월 16일
Hello,
I have a 22x1 array that I'd like to assign to a colorscale (jet) so that each value has a corresponding corresponding color
>> colorpost
colorpost =
-1.4721
-11.3430
23.4227
7.0674
-2.7839
42.3308
-2.6353
0.1617
6.3158
-20.6096
2.6023
3.1703
5.8185
-4.1358
6.9481
-5.1080
24.6877
-5.1542
-17.9669
1.8017
-23.3427
-15.8499
But when I do the following it doesn't work
>> c=jet(colorpost)
Error using /
Matrix dimensions must agree.
Error in jet (line 23)
u = [(1:1:n)/n ones(1,n-1) (n:-1:1)/n]';
I've seen a similar problem here but it doesn't seem to help me since that array is all integers https://www.mathworks.com/matlabcentral/answers/897552-get-colormap-values-corresponding-to-array-values

채택된 답변

Walter Roberson
Walter Roberson 2022년 11월 15일
colorpost = [
-1.4721
-11.3430
23.4227
7.0674
-2.7839
42.3308
-2.6353
0.1617
6.3158
-20.6096
2.6023
3.1703
5.8185
-4.1358
6.9481
-5.1080
24.6877
-5.1542
-17.9669
1.8017
-23.3427
-15.8499
];
cmap = jet();
numcol = size(cmap,1);
cps = floor(rescale(colorpost, 1, numcol));
colorized_cp = permute(cmap(cps,:), [1 3 2]);
image(colorized_cp)

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 11월 15일
Try this:
colorpost =[...
-1.4721
-11.3430
23.4227
7.0674
-2.7839
42.3308
-2.6353
0.1617
6.3158
-20.6096
2.6023
3.1703
5.8185
-4.1358
6.9481
-5.1080
24.6877
-5.1542
-17.9669
1.8017
-23.3427
-15.8499];
% Specify the number of colors to be the same as the number of elements in colorpost.
numColors = numel(colorpost)
% Create a colormap.
cmap = jet(numColors);
% Assume min value is cmap(1, :) and max value is cmap(end, )
% Get color sorted in the same way as colorpost (or you could make a dictionary)
[sortedColorpost, sortOrder] = sort(colorpost, 'ascend');
assignedColors = cmap(sortOrder, :);
Is it what you want?
  댓글 수: 2
bsriv
bsriv 2022년 11월 15일
perfect thank you!
Walter Roberson
Walter Roberson 2022년 11월 15일
This assigns one color per element, even if two elements are close or even identical. The color is not proportional to the value.
The solution I gave scales entries according to relative value through the span of values, and so is suitable for color representing relative value.

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

카테고리

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