How to define Matlab colors

2 次查看(过去 30 天)
Hi,
I have updated my matlab code in version 2018a Matlab. But when I try to execute this updated code in Matlab 2009a version; this error occurs:
Bad property value found.
Object name: line
Property name: 'Color'
The error occurs in the below Matlab line:
set([hline1; hline2], {'color'}, {'[0, 0, 1]';'[1, 0, 0]';'[0, 1, 0]';'[1, 1, 0]';'[0, 0.75, 0.75]';'[0.75, 0, 0.75]';'[0.635, 0.0780, 0.1840]';'[0.8500, 0.3250, 0.0980]';'[0.25, 0.25, 0]'; '[0.25, 0.25, 0.3]';'[0.25, 0.25, 0.5]';'[0, 0, 0]'});
By the way; I must use 12 colors to plot my figure. So I have defined the colors as in the above line..
How can I solve this problem?
  3 个评论
SEVAL DONERTAS
SEVAL DONERTAS 2019-1-2
编辑:Walter Roberson 2019-1-2
My full code;
f
igure;[haxes,hline1,hline2] = plotyy(dat_s1,[M1K1_norm_1 M1K2_norm_1 M1K1_norm_2 M1K2_norm_2 M1K1_norm_3 M1K2_norm_3 M1K1_norm_4 M1K2_norm_4], dat_s1,[T1 T2 T3 T4]);
set(haxes(1),'XLim',[T1A T1B],'Linewidth', 1.5);
set(haxes(2),'XLim',[T1A,T1B]);
set(haxes(1),'YLim',[0 1.3], 'FontSize', 16);
set(haxes(1),'YTick',[0:0.13:1.3]);
set(haxes(2),'YLim',[-60 90], 'FontSize', 16);
set(haxes(2),'YTick',[-60:15:90])
set(hline1,'LineWidth',3);
set(hline2,'LineWidth',3);
set(haxes, 'FontSize',15,'LineWidth',2)
set([hline1; hline2], {'color'}, {'[0, 0, 1]';'[1, 0, 0]';'[0, 1, 0]';'[1, 1, 0]';'[0, 0.75, 0.75]';'[0.75, 0, 0.75]';'[0.635, 0.0780, 0.1840]';'[0.8500, 0.3250, 0.0980]';'[0.25, 0.25, 0]'; '[0.25, 0.25, 0.3]';'[0.25, 0.25, 0.5]';'[0, 0, 0]'});
Walter Roberson
Walter Roberson 2019-1-6
Please do not close questions that have an answer. The volunteers spend time researching and answering questions, and it is not fair to the volunteers when their work suddenly disappears.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-1-2
If you are going to set with character vectors then you need to use color names or the color abbreviations such as 'b'.
When configuring numeric values, do not use '' around the value.
set([hline1; hline2], {'color'}, {[0, 0, 1]; [1, 0, 0]; [0, 1, 0]; [1, 1, 0]; [0, 0.75, 0.75]; [0.75, 0, 0.75]; [0.635, 0.0780, 0.1840]; [0.8500, 0.3250, 0.0980]; [0.25, 0.25, 0]; [0.25, 0.25, 0.3]; [0.25, 0.25, 0.5] ; [0, 0, 0]});
Note that this will give you an error unless [hline1; hline2] together refers to 12 handles for primitive line objects. Each primitive line object can have only one Color value. It is not possible to configure multiple colors for a single primitive line object.
  2 个评论
SEVAL DONERTAS
SEVAL DONERTAS 2019-1-2
But when I run this code in version 2018a; there is no problem. When I run in 2009a version, I come across error. Can be a problem related to version mismatch?
Walter Roberson
Walter Roberson 2019-1-2
No, it is a bug in your code that you have been unlucky to not have noticed before. There is no documented meaning for using character vectors of numeric values to define colors. Anything could happen.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by