본문 바로가기

MATLAB/ㄴ 앱 디자이너

Switch 토글 버튼을 이용해서 Graph를 Switching하기

 


% Value changed function: Switch

function SwitchValueChanged(app, event)
    value = app.Switch.Value;
     if ~isvalid(app.UIAxes)
          app.UIAxes = uiaxes(app.GraphPanel);
          xlabel(app.UIAxes, 'Wavelength (nm)')
          app.UIAxes.XTick = [0 0.25 0.5 0.75 1];
          app.UIAxes.XTickLabel = {'200'; '400'; '600'; '800'; '1000'};
          app.UIAxes.FontSize = 24;
          app.UIAxes.Position = [1 0 852 538];
     end

     switch value
     case 'Generated'
          title(app.UIAxes, 'Generated')
          xlabel(app.UIAxes, 'Wavelength (nm)')
          ylabel(app.UIAxes, 'Ψ in degrees')
          app.UIAxes.YTick = [0 0.2 0.4 0.6 0.8 1];
          app.UIAxes.YTickLabel = {'0'; '20'; '40'; '60'; '80'; '100'};
          app.UIAxes.Visible = 'on';
    case 'Experimental'
          title(app.UIAxes, 'Experimental')
          xlabel(app.UIAxes, 'Wavelength (nm)')
          ylabel(app.UIAxes, 'Δ in degrees')
          app.UIAxes.YTick = [0 0.25 0.5 0.75 1];
          app.UIAxes.YTickLabel = {'0'; '50'; '100'; '150'; '200';};
          app.UIAxes.Visible = 'on';
     end
end