if分の使い方について

2 vues (au cours des 30 derniers jours)
Ibuki Takahashi
Ibuki Takahashi le 6 Sep 2021
MATLABのGUIアプリを作成しております。
Slider Swichを用いて、ある機能のオン・オフを実装したいと考え、if文によってプログラムを作成しようと考えました。
しかし、if文を用いたコードでは、true,falseが正しく判定されず、組むことができませんでした。
スイッチを用いた、if文の正しい書き方があれば教えていただきたいと考えております。
よろしくお願いします。

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 6 Sep 2021
Modifié(e) : Atsushi Ueno le 6 Sep 2021
Slider Swichを使ってみましたが、デフォルトではON時の値が'on'、OFF時の値が'off'という文字列になっています。なので、IF文に直接app.Switch.Valueを与えても判断してくれません。下記コードの様にapp.Switch.Valueの値を文字列として判断すれば、true,falseが正しく判定されます。
% Value changed function: Switch
function SwitchValueChanged(app, event)
if(strcmp(app.Switch.Value,'On'))
app.Lamp.Color = [0 1 0];
else
app.Lamp.Color = [0 0 0];
end
end

Plus de réponses (0)

Catégories

En savoir plus sur App Designer を使用したアプリ開発 dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!