フィルターのクリア

Simulink Enumeration

3 ビュー (過去 30 日間)
B. J.
B. J. 2011 年 10 月 21 日
Hello,
I am trying to do a simple multiport switch. My control is a numeric value.
If 1 is selected, I want my output to be 'Red'. If 2, I want 'Yellow', ect.
I have tried creating a class object for Colors. (thinking this isn't helping)
classdef Colors
properties
R = 0;
G = 0;
B = 0;
end
methods
function c = Colors(r,g,b)
c.R = r; c.G = g; c.B = b;
end
end
enumeration
Red(1, 0, 0)
Orange(1, .5, 0)
Yellow(1, 1, 0)
Green(0, 1, 0)
Blue(0, 0, 1)
Indigo(.2, 0, .8)
Violet(1, 0, 1)
end
end
thus, when I type Colors.Red, I get Red as my output.I used the Enumerated Constant, of output Colors and value Colors.Red. I get error "Initialization commands cannot be evaluated."
Any help would be great, my end goal is to pass a value out of "Red","Yellow"..ect. If I do this as a char or enumerated state I don't care.
thanks.

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 21 日
  2 件のコメント
B. J.
B. J. 2011 年 10 月 21 日
This what what I used to create my class Colors, but I'm having trouble calling it from that point. I cannot seem to pull out "orange" for example. I get constructor errors saying "colors constructor
a = Colors(1, .5, 0)
??? Error using ==> Colors
Cannot call the constructor of 'Colors' outside of its enumeration block.
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 21 日
Should you use a=Colors.Orange? Then you can check a.R, a.G and a.B

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


Kaustubha Govind
Kaustubha Govind 2011 年 10 月 24 日
I don't think you can use this kind of enumerated class in Simulink. Simulink enumerated types need to inherit from Simulink.IntEnumType. See Defining Simulink Enumerations.

カテゴリ

Help Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by