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:
54 ビュー (過去 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]
1 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!