Baixe o app para aproveitar ainda mais
Prévia do material em texto
Guide Prof. Cláudio A. Fleury Abr - 2009 Interface Gráfica para Aplicações Matlab Iniciando Objetos de Controle Push Button Radio Button Checkbox Toggle Button List Box Axes Slider Edit Text Popup Menu Static Text (Label) Frame P.O.O. • Objetos – Propriedades – Ações estofamento cor material design tamanho Propriedades dos Objeto Propriedades dos Objeto P.O.O. Enable Visible on off inactive on off P.O.O. P.O.O. WindowStyle modal normal Resize modal normal onoff P.O.O. - Ações Ação disparada pelo controle ao ser clicado: Alterações em Tempo de Execução Alterações em Tempo de Execução get(handles.edit1,'String') Tag Alterações em Tempo de Execução set(handles.text1,'String',C) Interface Gráfica para Usuário* * GUI – Graphical User Interface Criador de GUI • Carregando o guide: Criador de GUI Criador de GUI Criando os Controles Componentes 2 Edit Text 4 Static Text4 Static Text 1 Pushbutton Interface até agora! Ajustando as Propriedades Interface até agora! • Melhorando o aspecto visual da interface: Ajustando as Propriedades Interface até agora! Save it!Save it! Acrescentando Código • Funções callback Acrescentando Código • Programa para os campos de textos function input1_editText_Callback(hObject, eventdata, handles) % hObject - é a alça (handle) para input1_editText (ver GCBO) % eventdata - reservado – a ser definido no futuro do MATLAB % eventdata - reservado – a ser definido no futuro do MATLAB % handles – estrutura com alças e dados do usuário (ver GUIDATA) % Dicas: % % get(hObject,'String') retorna o conteúdo de input1_editText c/ texto % str2double(get(hObject,'String')) retorna conteúdo de input1_editText % como um double Acrescentando Código • Programa para os campos de textos function input1_editText_Callback(hObject, eventdata, handles) % armazena o conteúdo de input1_editText como uma string. Se a string % não for um número então a entrada será esvaziada input = str2num(get(hObject,'String'));input = str2num(get(hObject,'String')); % verifica se a entrada está vazia. Se sim, input1_editText recebe zero if (isempty(input)) set(hObject,'String','') msgbox(‘Digite um valor numérico…’, ‘Atenção’); end guidata(hObject, handles); Acrescentando Código • Programa para o botão % --- Executes on button press in add_pushbutton. function add_pushbutton_Callback(hObject, eventdata, handles) % hObject handle to add_pushbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = get(handles.input1_editText,'String'); b = get(handles.input2_editText,'String'); % a and b are variables of Strings type, and need to be converted % to variables of Number type before they can be added together total = str2num(a) + str2num(b); c = num2str(total); % need to convert the answer back into String type to display it set(handles.answer_staticText,'String',c); guidata(hObject, handles); Desligando Comentários Automáticos Executando a GUI Executando a GUI Primeiro Programa Matlab com GUI Exercício • Fazer um programa Matlab com GUI para plotar o gráfico de vários sinais e respectivos espectros, conforme a figura: Dúvidas [time,number,pressure,raininput] = textread(’rain.txt’,'%s %d %f %f’,'delimiter’,',’,'headerlines’,4); That’s all folks! Prof. Cláudio A. Fleury – Abr/2009 prof.claudio.2008.2@gmail.com
Compartilhar