Does anyone know how to create colors?

Hello everyone,
How can I create/ have different colors from the standard ones (i.g. 'g','r','b','m'...)?
Thank you.

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 8월 16일

0 개 추천

Colours can be specified by rgb-values in a 1-by-3 array with values between zero and one. So for example:
light_blue = [0.5 0.5 1];
plot(0:12,randn(1,12),'color',light_blue)
HTH

댓글 수: 7

Pul
Pul 2021년 8월 16일
It gives me error when I try it.
Try
light_blue = [0.5 0.5 1];
plot(1:12,randn(1,12),'color',light_blue)
Pul
Pul 2021년 8월 17일
Now it works, thank you.
Last question: given that values have to be between zero and one, if I want to have another color (not shades of blue as in your example), what do I have to do?
Thanks.
That's as simple as:
red_I = 0.8;
green_I = 0.4;
blue_I = 0.2;
rgb_color = [red_I,green_I,blue_I];
That is first component red, second green and third blue intensities. From there it is easy to come up with the approximate values for the colour you want, but some adjustments to get what you really want is typically necessary...
Pul
Pul 2021년 8월 17일
Okay, got it.
Thank you.
Bjorn Gustavsson
Bjorn Gustavsson 2021년 8월 17일
@Image Analyst, I have a poor short-time memory - but that was a bit extreme even for me.
@Pul, Great. Have a look at the file exchange for color-manipulation-tools that might help you with more demanding color-designing work - always look there for tools that solve or nearly solve your problems (it has saved me many months of work)!
Pul
Pul 2021년 8월 17일
@Bjorn Gustavsson Okay, thank you!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 8월 16일

1 개 추천

Try this:
% Create 20 different colors according to the jet color map.
colors = jet(20);
% Plot randome data, each curve with one of the colors we created.
% Basically you have to get the color equal to one row from colors.
for k = 1 : size(colors, 1)
thisColor = colors(k, :);
y = rand(1, 5) + 2 * k; % Create some random data.
plot(y, '.-', 'Color', thisColor, 'LineWidth', 4, 'MarkerSize', 50); % Plot this one curve.
hold on; % Don't let subsequent plots blow away this one we just drew.
end
grid on;
xlabel('X');
ylabel('Y');

댓글 수: 3

Pul
Pul 2021년 8월 16일
Thank you!
But how can I choose the color I want to plot among them?
@Pul, like @Bjorn Gustavsson said, if you have some specific color you want to use, then you can do
light_blue = [0.5 0.5 1];
plot(1:12, randn(1,12), 'color', light_blue)
If you have created a list of lots of colors, like in my example, and, for example, you want to make the curve with the 10th color from the list, you can do
plot(y, '.-', 'Color', colors(10, :), 'LineWidth', 4, 'MarkerSize', 50); % Plot this one curve.
My demo showed that, where I plotted every color from k=1 to k=20.
Pul
Pul 2021년 8월 17일
@Image Analyst Yes, clear, I got it.
Thank you!

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

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

Pul
2021년 8월 16일

댓글:

Pul
2021년 8월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by