if分の使い方について

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

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 6 Sep 2021
Edited: Atsushi Ueno on 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

More Answers (0)

Categories

Find more on App Designer を使用したアプリ開発 in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!