if分の使い方について
8 views (last 30 days)
Show older comments
MATLABのGUIアプリを作成しております。
Slider Swichを用いて、ある機能のオン・オフを実装したいと考え、if文によってプログラムを作成しようと考えました。
しかし、if文を用いたコードでは、true,falseが正しく判定されず、組むことができませんでした。
スイッチを用いた、if文の正しい書き方があれば教えていただきたいと考えております。
よろしくお願いします。
0 Comments
Accepted Answer
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
0 Comments
More Answers (0)
See Also
Categories
Find more on 実験計画法 (DOE) 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!