Can i get 12 different colors for 12 different variables in matlab? So far I could only get 6 colors because i don't know the values for the other colors:

조회 수: 93 (최근 30일)
if(strcmp(matrix(i,2),"C1")==1)
redundant sRGB matrix values replaced with ...
end
fs = 10;
score = repmat(linspace(1,6,12).',[1 3]);
matrix = ["" "C1"; "" "C2"; "" "C3"; "" "C4"; "" "C5"; "" "C6"; ...
"" "C7"; "" "C8"; "" "C9"; "" "C10"; "" "C11"; "" "C12"];
lb = strcat(repmat("Test string ",[12 1]),matrix(:,2));
%I am trying to classify each C by a different color but I only know 6 color numbers without adding decimals. Is there a way to
%add
%12 different colors in this format? i.e. [1.5, val = 0, 1.2]

채택된 답변

DGM
DGM 2023년 2월 28일
편집: DGM 2023년 3월 1일
I'm not really sure what you're asking for or why. The thing you have is a set of repeated pairs. The thing you're asking for [1.5 0 1.2] isn't a valid unit-scale color tuple. Is val always zero? If not, will it also exceed [0 1]? Is there some particular meaning to the sequence and scale of the colors? If so, we'd obviously need to know.
If you just need 12 unique colors, you can use one of the colormap generator functions like jet(), parula(), etc to generate a map of a specified length. If you want to group them in pairs, you can use something like the attached function.
The rest of this can be cleaned up to eliminate the repeated code. Normally, you can use a switch-case structure instead of repeated if-else tests to do this, but in this case, the conditionally-executed code is identical except for one parameter.
% some placeholder inputs
fs = 10;
score = repmat(linspace(1,6,12).',[1 3]);
matrix = ["" "C1"; "" "C2"; "" "C3"; "" "C4"; "" "C5"; "" "C6"; ...
"" "C7"; "" "C8"; "" "C9"; "" "C10"; "" "C11"; "" "C12"];
lb = strcat(repmat("Test string ",[12 1]),matrix(:,2));
% generate a color table of appropriate length
colortable = tab20(12);
% demonstrate
xlim([0 10])
ylim([0 7])
hold on
for i = 1:12
% just get the trailing numeric part
thisclass = str2double(strrep(matrix(i,2),'C',''));
% print the text
text(score(i,1),score(i,2),score(i,3),lb(i), ...
'Color',colortable(thisclass,:),'fontsize',fs,'FontWeight','bold');
end
The attached function is from here. There are many other similar tools on the File Exchange.
  댓글 수: 9
Stephen23
Stephen23 2023년 3월 2일
@Chanille: i highly recommend watching this video about the developing the new MatPlotLib colormaps:
It is an compact, entertaining, yet very educational introduction to the world of color perception modelling.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by