Hi everyone, I inted to to make a multiple plot with with predefined color code.
Could you please assit me, on how to include the code to define the colors of my plot instead of using the matlab default color
clear all; close all; clc
a=[6.5 10 12 16];b=linspace(1, 10);
for i=1:4;
aa=a(i)
y=1./(exp(-aa./b)+ 1);
plot(b, y)
hold on
end

 採用された回答

Walter Roberson
Walter Roberson 2022 年 8 月 27 日

0 投票

If you are using a new enough version of MATLAB, see colororder
If you are using an older version of MATLAB, you could change the ColorOrder property of the axes.
Or... each time you plot() you could pass in a 'Color' option with the color you want. For example,
cmap = jet(4);
a=[6.5 10 12 16];b=linspace(1, 10);
for i=1:4;
aa=a(i)
y=1./(exp(-aa./b)+ 1);
plot(b, y, 'color', cmap(i, :), 'DisplayName', string(i));
hold on
end
aa = 6.5000
aa = 10
aa = 12
aa = 16
legend show

5 件のコメント

Grace
Grace 2022 年 8 月 27 日
Thank you Walter for your reply..
Actuually, I want to specify the color code.
For example 'r' '-k' 'g' and '-b'.
How can I achieve this?
Thank you
Walter Roberson
Walter Roberson 2022 年 8 月 27 日
index a cell array
Grace
Grace 2022 年 8 月 27 日
How can i do it pls?
Walter Roberson
Walter Roberson 2022 年 8 月 27 日
cc = {'.r', '-k', '--g', ':b'};
a = [6.5 10 12 16]; b = linspace(1, 10);
for i=1:4;
aa=a(i)
y=1./(exp(-aa./b)+ 1);
plot(b, y, cc{i}, 'DisplayName', string(i));
hold on
end
aa = 6.5000
aa = 10
aa = 12
aa = 16
legend show
Grace
Grace 2022 年 8 月 28 日
Thanks a million times

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2022 年 8 月 27 日

コメント済み:

2022 年 8 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by