Download presentation

Presentation is loading. Please wait.

Published byChristopher Gallegos Modified over 2 years ago

1
Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB Graphic User Interface (GUI)Basics

2
GUI Basics: 1.uicontrols Edit Text Static Text Label Push Button Radio Button Button Group Slider Check Box Panel List Box Pop-up Menu Toggle Button Table Axes Menu Toolbar 2Modeling & Simulations

3
3 Edit Text function edittext1_Callback(hObject, eventdata, handles) s = get(hObject, 'String'); set(hObject, String, s); % if number, use num2str or str2num n = str2num(get(hObject,'string')); if isnan(n) errordlg(Enter a numeric value',Input Error','modal'); uicontrol(hObject); return end Pushbutton function pushbutton1_Callback(hObject, eventdata, handles) plot( ……… ); …………..; end Modeling & Simulations

4
4 Radiobutton function radiobutton1_Callback(hObject, eventdata, handles) if (get(hObject,'Value') == get(hObject,'Max')) do something else do nothing end set(handles.radiobutton1,'Value','Max) end Checkbox function checkbox1_Callback(hObject, eventdata, handles) if (get(hObject,'Value') == get(hObject,'Max')) %do something else %do something else end % can be used in a groupbox with other uicontrols Modeling & Simulations

5
5 Buttongroup function uibuttongroup1_SelectionChangeFcn(hObject,eventdata) switch get(eventdata.NewValue,'Tag) case 'radiobutton1' %code; case 'radiobutton2' %code; case 'togglebutton1 %radiobuttons and togglebuttons in group %code; case 'togglebutton2 %code; otherwise % Code for when there is no match. end Slider function slider1_Callback(hObject, eventdata, handles) val = get(hObject,'Value'); %[0 1] …………. %set it to another interval if required as: min+(max-min)*val; end Modeling & Simulations

6
6 Panel function uipanel1_ResizeFcn(hObject, eventdata, handles) set(hObject,'Units','Points) % Was normalized panelSizePts = get(hObject,'Position'); % Now in points panelHeight = panelSizePts(4); set(hObject,'Units','normalized'); % Now normalized again % Keep fontsize in constant ratio to height of panel newFontSize = 10 * panelHeight / 115; % Calculated in points buttons = get(hObject,'Children'); set(buttons(1),'FontSize,newFontSize);% Resize the first button % Do not resize the other button for comparison end Listbox function listbox1_Callback(hObject, eventdata, handles) index = get(hObject,'Value'); list = get(hObject,'String'); item = list{index}; set(handles.listbox1,'Value',2) end Modeling & Simulations

7
7 Popupmenu % Using value function popupmenu1_Callback(hObject, eventdata, handles) val = get(hObject,'Value'); switch val case 1 % code case 2 %code end % Using String function popupmenu1_Callback(hObject, eventdata, handles) val = get(hObject,'Value'); list = get(hObject,'String'); str = list{val}; % Convert from cell array to string end Modeling & Simulations

8
8 Problem I Plancks Radiation Law is formulated as: where R is the spectral radiance and T is temperature in Kelvins and is wavelength of radiation 1) Simulate the Law by plotting R vs for different values of T. range = 0.01m to 8m T range = 500K to 2500K and let user change the temperature T 2) Display temperature at each step. 3) Display maximum Spectral Radiance R at each step 4) Display wavelength at at each R 5) Draw a vertical line between R and corresponding wavelength at each step.

9
9Modeling & Simulations Problem II T( C) x The above table gives the viscosity ( ) of air at different temperatures (T) Viscosity is expresed as: C and S are constants Determine C and S by curve-fitting using the above equation. Plot a graph between T and for given data (only markers) and plot a line graph using the equation. Calculate the error.

10
10 END Modeling & Simulations

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google