1 / 88

Graphic Objects figure axes 2D-plot 3D-plot axis labels title GUI objects pushbutton

Graphic Objects figure axes 2D-plot 3D-plot axis labels title GUI objects pushbutton toggle edit text menu. Continuing with our GUI project. Sliders. Sliders provide an easy way to gradually change values between a given range. Three ways to move the slider. Sliders.

josiah-ward
Download Presentation

Graphic Objects figure axes 2D-plot 3D-plot axis labels title GUI objects pushbutton

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphic Objects • figure • axes • 2D-plot • 3D-plot • axis labels • title • GUI objects • pushbutton • toggle • edit • text • menu

  2. Continuing with our GUI project

  3. Sliders • Sliders provide an easy way to gradually change values between a given range. Three ways to move the slider

  4. Sliders • The user has three possible way to change the position of the slider • Click the arrow buttons => small value changes • Click the trough => large value changes • Click and drag the slider => depends on user • The default changes are 1% and 10%

  5. We must set a value between Min and Max Sliders • The range of the slider is defined with the Min and Max uicontrol properties. • The amount of change related to an user click is controlled with the SliderStepproperty which is a two element vector ([0.01 0.1] default) hToVertSlider= uicontrol('Style','slider',... 'Position',[160 10 20 120],... 'Min',10,... 'Max',20,... 'Value',15,... 'SliderStep',[0.1 0.25],... 'Callback','')

  6. Sliders • Given the setting from Min, Max and SliderStep the amount of change to the current Value are as follow: • For an arrow click: • Value = Value + SliderStep(1) * (Max – Min) • 16 = 15 + 0.1 * (20 - 10) • For a trough click: • Value = Value + SliderStep(2) * (Max – Min) • 17.5 = 15 + 0.25 * (20 - 10)

  7. Step V– the speed slider uicontrol('style' ,'slider',.... 'position',[130 10 450 30],... 'tag' ,'speedSlider',... 'max' ,pi/2,... 'min' ,0.01,... 'value' ,pi/4);

  8. Step V– the speed slider uicontrol('style' ,'slider',.... 'position',[130 10 450 30],... 'tag' ,'speedSlider',... 'max' ,pi/2,... 'min' ,0.01,... 'value' ,pi/4); What about the callback?

  9. Text and editable text • Static texts are commonly used to give instructions or to display other controllers values (such as sliders) • …’Style’,’text’,… • Static text can not execute callbacks. • Editable texts gets string input from the GUI user. • When the user enters the edit field and change its content, only the String property is affected. • Editable text can execute callbacks

  10. Step VI – the text frame uicontrol('style' ,'text',... 'string' ,'C',... 'tag' ,'C_title',... 'position' ,[490 290 60 70],... 'backgroundColor','y'); What about the callback?

  11. Step VII – the edit window uicontrol('style' ,'edit',... 'string' ,'1',... 'value' ,1,... 'tag' ,'C',... 'position',[500 300 40 40],... 'callback', {@getC}); function getC(calling_button, eventData) s = get(calling_button,'string'); set(calling_button,'value',str2double(s)); end

  12. Selected Radio Buttons • Radio buttons are similar to checkboxes but designed to specify options that aremutually exclusive like inmultiple-choice questions hToRadio1 = uicontrol('Style', 'radio',... 'Position',[20 300 120 20],... 'String','Option1',... 'Callback', {@turnOffTheOtherButtons},... 'Value',1)

  13. Function turnOffTheOtherButtons h = findobj('Tag','option1'); set(h,'Value',0); : : Do we need a different function for each button?

  14. Step VIII – the radio buttons uicontrol('style' ,'radio',... 'string' ,'surf',... 'callback', {@plotTypeButtons},... 'tag' ,'plot_type',... 'position',[490 250 80 30],... 'value' ,1,... 'userdata',1); uicontrol('style' ,'radio',... 'string' ,'contour3',... 'callback', {@plotTypeButtons},... 'tag' ,'plot_type',... 'position',[490 220 80 30],... 'value' ,0,... 'userdata',0);

  15. Step VIII – the radio buttons function plotTypeButtons(calling_button, eventData) handles = findobj('tag','plot_type'); set(handles,'value',0); set(calling_button,'value',1); end

  16. Step IX - Now lets use it function run(main_axes, small_axes) onOff = findobj('tag','onOff'); speedSlider = findobj('tag','speedSlider'); C_window = findobj('tag','C'); close_button = findobj('tag','close'); type_handels = findobj('tag','plot_type');

  17. Step IX - Now lets use it function run(main_axes, small_axes) onOff = findobj('tag','onOff'); speedSlider = findobj('tag','speedSlider'); C_window = findobj('tag','C'); close_button = findobj('tag','close'); type_handles = findobj('tag','plot_type'); How does type_handles differ from the other handles?

  18. kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = 0.0001; end end pause(0.1); end

  19. kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = 0.0001; end end pause(0.1); end

  20. kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = 0.0001; end end pause(0.1); end

  21. kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = 0.0001; end end pause(0.1); end

  22. kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = 0.0001; end end pause(0.1); end fig = findobj('tag','the_figure'); close(fig); end

  23. Step XI – Adding color map menu cm = uimenu('tag','colorMap','label','Color Map');

  24. Step XI – Adding color map menu cm = uimenu('tag','colorMap','label','Color Map'); uimenu(cm, 'label','jet', ‘callback',{@set_colorMap,jet}); uimenu(cm, 'label','hot', 'callback',{@set_colorMap,hot}); uimenu(cm, 'label','cool', 'callback',{@set_colorMap,cool}); function set_colorMap(calling_manu, eventData,colorMap) set(gcf,'colorMap',colorMap); parent = get(calling_manu,'parent'); all = get(parent,'children'); set(all,'checked','off'); set(calling_manu,'checked','on'); end

  25. Checkboxes • Checkboxes allow the user to turn on/off a number of independent options hToCheckBox = uicontrol('Style', 'checkbox',... 'Position',[20 450 120 20],... 'String','Check Box example‘, ... ‘Callback’,’’) • Note: the position is measured in pixels from the left-bottom corner of the figure

  26. Basics of Linear Algebra start with two examples: In 1st : We do not need Linear Algebra In 2nd : Linear Algebra is needed

  27. Consider a species where N represents number of individuals. This species reproduces with a very simple rule: in any generation t (t = 0,1,2,....), the population changes its size by a factor of R. Hence, at t+1 size of population is N(t+1) = R N(t). Question: if we start with a population of size N(0), what will be its size after t generations?

  28. Numerical computation (for two possible values of R)- gen=[1 2 3 4 5 6 7 8 9 10]; N0=100; %initial condition for populations n1=N0; R1=1.1; %Params for population 1 n2=N0; R2=0.9; %Params for population 2 for t=1:10 % numerical computation P1(t) = n1; n1 = n1*R1; %change pop 1 P2(t) = n2; n2 = n2*R2; %change pop 2 end plot(gen,P1,'or:',gen,P2,'^b-');

  29. P1 P2 if R>1, the population grows to infinity. if R<1 it decays to 0.

  30. Back to Question: if we start with a population of size N(0), what will be its size after t generations? In our case, the answer is trivial – no need for numerical computation: For every t N(t+1) = RN(t) Hence- N(t) = Rt N(0). In our example- N1(10) = 1.110 * 100 = 2.59 *100 = 259 N2(10) = 0.910 * 100 = 0.35 *100 = 35 In this case, there is an analytical solution

  31. Simple problems have analytical solutions Complex problems can be solved only with numerical computations

  32. For example, consider a species in which parameters are age-dependent. • Reproduction- • 1) age=0 (from birth to the age of 1) does not reproduce • 2) age=1 yields 2 offsprings • 3) age=2 yields 1.5 offsprings • Survival- • 4) 40% of age 0 survive to next generation • 5) 30% of age 1 survive to next generation • 6) 10% age 2 survive to next generation • 7) No females of age 3 survive.

  33. We may want to ask a questions like: what will be N(T) Here the answer is more complex, because the system is defined by several equations, not only one:Let Ni denote the number of individuals of age i.N0(t+1) = 2N1(t)+1.5N2(t)N1(t+1) = 0.4N0(t)N2(t+1) = 0.3N1(t)N3(t+1) = 0.1N2(t) N(t+1) = N0(t+1)+N1(t+1)+N2(t+1)+N3(t+1) We may want to ask additional questions like: when will the fraction of newborn stay constant, i.e : Find t such that N0(t)/N(t) = N0(t+1)/N(t+1) ?

  34. To solve this problem, we need techniques from Linear Algebra.Start by reviewing important concepts in Linear Algebra.Will come back to this problem later, after learning some Linear Algebra

  35. Matrix addition/substraction Suppose A=[ai,j] and B=[bi,j] are two m x n matrices. Then C=A+B is an m x n matrix where ci,j = ai,j+bi,j for 1 im, 1j n Example-

  36. Matrix addition/substraction Example with 3 matrices-

  37. Matrix Multiplication- Suppose A=[ai,k] is an mby lmatrix and B =[bk,j] is an lby n matrix. Then: C=A B is an m by n matrix with: This is small L in Italics In other words, in matrix C an element at place i,j is the result of multiplying the elements of row i in A by the elements of column j in B, and sum them up.

  38. Example- The multiplication is valid, because the number of columns in A is equal to the number of rows in B. The result is a matrix with 2 rows (number of rows in A) and 4 columns (number of columns in B). To find any element cij, we multiply the elements of the ith row in A by the elements of the jth column of B, and sum them- Third column elements in B Second row elements in A

  39. The other entries are found in a similar way, and we find-

  40. In Matrix multiplication, the order is important ! in other words, AB  BA: • Example:

  41. In Matrix multiplication, the order is important ! in other words, AB  BA: • Example:

  42. In Matrix multiplication, the order is important ! in other words, AB  BA: • Example where we reverse order of multiplication: (from previous slide)

  43. Check that you did it right Suppose A=[ai,k] is an mby lmatrix and B =[bk,j] is an lby n matrix. Then: C=A B is an m by n matrix with: Test 1 Test 1: Rows of first matrix = columns in second matrix

  44. Check that you did it right Suppose A=[ai,k] is an mby lmatrix and B =[bk,j] is an lby n matrix. Then: C=A B is an m by n matrix with: Test 2 Test 1: Columns of first matrix = rows in second matrix Test 2: dimensions of resulting matrix are the rows of first and columns of second

  45. If you multiply an array by a vector If the vector is a column vector – Always the vector must be on the right hand side C=AxB A B C=BxA Or the vector must be a row vector

  46. Writing a system of linear equations in matrix form Consider the following system of n equations with n variables xi, i=1..n. It is convenient to represent this system of equations in matrix form: Vector of Right Hand Side (RHS)Values Coefficient Matrix Matrix Multiplication Operator Vector of variables

  47. The system above can be also written in short: Vector of Right Hand Side (RHS)Values Coefficient Matrix Vector of variables Matrix Multiplication Operator Or simply-

  48. Power of Matrices Note- A must be a square matrix !!! Otherwise multiplication is undefined So far – Linear Algebra. Let’s move back to MATLAB

  49. Summary of what you know about Matrices in MatLab 1) A matrix is entered row-wise, with consecutive elements of a row separated by a space or a comma A=[ 1 2 3 ] A=[ 1, 2, 3 ] 2) Rows are separated by semicolons or carriage returns. B= [ 1 2 3 4 5 6 ] 3) Entire matrix must be enclosed within square brackets A=[ 1 2 3 ] 4) A single element of the matrix is accessed by specifying its index(ices), in round brackets. B(2,3)=6 5) Vector - a special case of a matrix. Can be column vector, or row vector 6) Scalar is a single element. It does not need brackets. 7) A null matrix is a matrix with no elements. It is defined by empty brackets []

  50. >> A=[ 1 2 5; 3 9 0] • A = • 1 2 5 • 3 9 0 >> u = [1 3 9] % row vector u = 1 3 9 >> v = [1; 3; 9] % column vector v = 1 3 9 >> transpose(v) % for convenience ans = 1 3 9 >> (v)’ % easier way to transpose ans = 1 3 9

More Related