Lamps in Matlab App Desinger

22 ビュー (過去 30 日間)
Aqib Habib Memon
Aqib Habib Memon 2022 年 10 月 22 日
回答済み: Cris LaPierre 2022 年 10 月 22 日
Hello.
I am trying to do something simple i.e. to change the lamp color whenever the switch is pressed.
The app has multiple components i.e. groups as seen in the screen shot
I am using the following callback function for the switch.
% Value changed function: Switch2
function Switch2ValueChanged(app, event)
value_S2 = app.Switch2.Value;
if strcmp(value_S2,'On')
app.Lamp.Color='g';
else
app.Lamp.Color='r';
end
end
The problem is , whenever a run the app and press the switch, it becomes red and doesnt change its color to green.

回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 10 月 22 日
Your code looks fine to me. A simple test app also works for me. Note that you want your lamp to turn green when it is turned on. By default, the lamp color is green to start with, and the switch by default is off. You can change the default setting of one to get the behavior you want.
I attached my test app.

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by