drop down, App Designer
조회 수: 1 (최근 30일)
이전 댓글 표시
Hy everyboby, I would like that in the second tab "evaporazione_mensile" changes the graph with pop-up menù. I wrote the function called "Lista_anniValueChanged", and I would like it changes the graph, but I can't do it and the graph is always the same.
Best regard Dario
% code
classdef app1_1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
Evporazione_annuale matlab.ui.container.Tab
UIAxes matlab.ui.control.UIAxes
Evaporazione_mensile matlab.ui.container.Tab
UIAxes2 matlab.ui.control.UIAxes
ANNILabel matlab.ui.control.Label
Lista_anni matlab.ui.control.DropDown
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
load('C:\Users\cecch\Documents\UNIVERSITA\Impianti Speciali Idraulici\Dati Portata\workspace_evaporazione.mat')
selectedTab = app.TabGroup.SelectedTab;
bar(app.UIAxes,1:12,E_pennman.Annuale,0.7,'r')
hold(app.UIAxes)
bar(app.UIAxes,1:12,E_Linacre.Annuale,0.5,'g')
bar(app.UIAxes,1:12,E_Visentini.Annuale,0.4,'b')
legend(app.UIAxes,'Penman','Linacre','Visentini','Location','southeast')
end
% Value changed function: Lista_anni
function Lista_anniValueChanged(app, event)
value = app.Lista_anni.Value
if ( value==1 )
plot(app.UIAxes2,1:3,5:7,'r')
else ( value==2 )
plot(app.UIAxes2,1:3,5:7,'b')
end
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 740 535];
app.UIFigure.Name = 'UI Figure';
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [41 17 657 499];
% Create Evporazione_annuale
app.Evporazione_annuale = uitab(app.TabGroup);
app.Evporazione_annuale.Title = 'Evaporazione_annuale';
app.Evporazione_annuale.BackgroundColor = [0.8 0.8 0.8];
% Create UIAxes
app.UIAxes = uiaxes(app.Evporazione_annuale);
title(app.UIAxes, 'Evaporazione')
xlabel(app.UIAxes, 'ANNI')
ylabel(app.UIAxes, 'mm ')
app.UIAxes.FontSize = 16;
app.UIAxes.Position = [33 -125 460 571];
% Create Evaporazione_mensile
app.Evaporazione_mensile = uitab(app.TabGroup);
app.Evaporazione_mensile.Title = 'Evaporazione_mensile';
% Create UIAxes2
app.UIAxes2 = uiaxes(app.Evaporazione_mensile);
title(app.UIAxes2, 'Evaporazione Mensile')
xlabel(app.UIAxes2, 'MESI')
ylabel(app.UIAxes2, 'mm')
app.UIAxes2.FontSize = 16;
app.UIAxes2.Position = [25 26 469 428];
% Create ANNILabel
app.ANNILabel = uilabel(app.Evaporazione_mensile);
app.ANNILabel.HorizontalAlignment = 'right';
app.ANNILabel.Position = [493 392 34 15];
app.ANNILabel.Text = 'ANNI';
% Create Lista_anni
app.Lista_anni = uidropdown(app.Evaporazione_mensile);
app.Lista_anni.Items = {'1', '2'};
app.Lista_anni.Editable = 'on';
app.Lista_anni.ValueChangedFcn = createCallbackFcn(app, @Lista_anniValueChanged, true);
app.Lista_anni.BackgroundColor = [1 1 1];
app.Lista_anni.Position = [542 388 100 22];
app.Lista_anni.Value = '1';
end
end
methods (Access = public)
% Construct app
function app = app1_1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
댓글 수: 0
채택된 답변
Ameer Hamza
2018년 5월 4일
app.Lista_anni.Value return a char, you need to modify the comparison like this
if ( value=='1' )
plot(app.UIAxes2,1:3,5:7,'r')
else ( value=='2' )
plot(app.UIAxes2,1:3,5:7,'b')
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!