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 Center および File ExchangeJust for fun についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by