How to define Matlab colors
2 views (last 30 days)
Show older comments
SEVAL DONERTAS
on 2 Jan 2019
Commented: Walter Roberson
on 6 Jan 2019
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 Comments
Walter Roberson
on 6 Jan 2019
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.
Accepted Answer
Walter Roberson
on 2 Jan 2019
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 Comments
Walter Roberson
on 2 Jan 2019
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.
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!