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:

79 次查看(过去 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 中查找有关 Blue 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by