if分の使い方について
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Ibuki Takahashi
 il 6 Set 2021
  
    
    
    
    
    Modificato: Atsushi Ueno
      
 il 6 Set 2021
            MATLABのGUIアプリを作成しております。
Slider Swichを用いて、ある機能のオン・オフを実装したいと考え、if文によってプログラムを作成しようと考えました。
しかし、if文を用いたコードでは、true,falseが正しく判定されず、組むことができませんでした。
スイッチを用いた、if文の正しい書き方があれば教えていただきたいと考えております。
よろしくお願いします。
0 Commenti
Risposta accettata
  Atsushi Ueno
      
 il 6 Set 2021
        
      Modificato: Atsushi Ueno
      
 il 6 Set 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 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
