Bad property value found

4 次查看(过去 30 天)
bafflingbill23
bafflingbill23 2016-4-25
编辑: dpb 2016-4-26
I am using GUIDE (GUI) and I am getting this error:
Error using set
Bad property value found.
Object Name: uicontrol
Property Name: 'BackgroundColor'.
The line that is giving me the error is:
set(handles.text410, 'BackgroundColor', b{4,
10});
b is a cell of colors and b{4, 10} = 'Orange'
I have a bunch of text boxes, and I don't know why it is giving me this error. I have 45 previous set statements with the same format that all work perfectly. Also, I am positive I have the correct tag.
Thanks so much in advance!
  2 个评论
Mike Garrity
Mike Garrity 2016-4-25
MATLAB Graphics knows a fairly limited number of colors by name. Orange isn't one of them. You can get other colors by using numeric RGB values.
Stephen23
Stephen23 2016-4-25
编辑:Stephen23 2016-4-25
The list of colornames recognized by MATLAB:
I don't see "orange" on that list.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2016-4-25
编辑:dpb 2016-4-26
'Orange' is not one of the named colors; only one of the eight 'yellow', 'magenta', 'cyan', 'red', 'green', 'blue', 'white', 'black' have common names; you'll have to use the numeric RGB triplet form in your assignment instead or make the array an enumeration class (altho I've not tested the HG property value will accept one for certain, left as "exercise for the student" :) )
ADDENDUM
While one can make enumerations work, I'm not terribly adept but the only way I got working shortly is pretty klunky to use. Maybe somebody else can improve on the following (adapted from a TMW example)
>> type Colors
classdef Colors
properties
R = 0;
G = 0;
B = 0;
RGB=[0 0 0];
end
methods
function c = Colors(r, g, b)
c.R = r; c.G = g; c.B = b;
c.RGB= [c.R c.G c.B];
end
end
enumeration
Orange (222/255,125/255,0)
end
end
>>
Can manage to use this as
>> plot(x,y,'color',Colors.Orange.RGB)
>>
But this seems to me to require too much intimate knowledge of the class to be desirable. Need some way to be able to return the desired RGB vector from just the name but I couldn't figure out a syntax to do that in the short time I've played with it. (If you can't tell, I'm not an OO kinda' guy... :) )
  2 个评论
Stephen23
Stephen23 2016-4-26
Simply use my FEX submission http://www.mathworks.com/matlabcentral/fileexchange/48155-convert-between-rgb-and-colornames to select the color by name, and return its RGB values:
[~,RGB] = colornames('CSS','Orange')
It supports lots of standard sets of named colors, such as CSS, HTML, RAL, etc. The colors can be specified by name, or by matching to the closest RGB values.
dpb
dpb 2016-4-26
编辑:dpb 2016-4-26
Very nice, Stephen--useful, indeed. The only nit I see is the need for a temporary in the subject application as there's no syntax to use the second return value in an argument. Could write a wrapper or define an anonymous function to handle it, of course.
Still seems there ought to be a way to get an enumeration to simply return the values, though, but I don't have the time to try to keep delving into syntax at the moment.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by