1 / 13

Lec 16 Chapter 10 Oct 25, 10 completion of recursion examples HW # 4, problem 3 Chapter 10, user

Lec 16 Chapter 10 Oct 25, 10 completion of recursion examples HW # 4, problem 3 Chapter 10, user interface design examples. Events activating the key board >> a = waitforbuttonpress In response, Matlab displays a figure window.

marlo
Download Presentation

Lec 16 Chapter 10 Oct 25, 10 completion of recursion examples HW # 4, problem 3 Chapter 10, user

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. Lec 16 Chapter 10 Oct 25, 10 • completion of recursion examples • HW # 4, problem 3 • Chapter 10, user interface design examples

  2. Events • activating the key board • >>a = waitforbuttonpress • In response, Matlab displays a figure window. • when you place the cursor inside the window and press down the mouse, the variable is set to 0 and the window is minimized. • instead, if you press a key, a is set to 1, and you can also extract that key using • >> get(gcf, ‘CurrentChar’)

  3. Menus and other choices >> items = {‘Car’, ‘Truck’, ‘Motorcycle’, ‘delete’, ‘QUIT’}; >> menu (‘Next vehicle:’, items) Clicking on car returns 1, truck 2 etc. QUIT closes the menu.

  4. The same functionality can be derived in other ways. >> questdlg(‘Does this make sense?’, ‘A question for you’) generates the following dialog box: Clicking on Yes (No) generates a string ‘Yes’ (‘No’).

  5. Character input >> textread('text1.txt', '%s', 'delimiter', ' '); >> foo = textread('text1.txt', '%s', 'delimiter', ' '); >> listdlg('liststring', foo) Now selecting a set of string from the box will create an array of selectd indices. >> listdlg('liststring', foo) ans = 1 4 5 8

  6. Text Box inputs Here is a way to create a text box: Suppose the user enters the information as follows: Then, a becomes: a = 'Joe' '1/1/2010' '8'5''

  7. A simple interactive program Write a program in Matlab that asks a user to guess an integer between 1 and N for some N, and repeatedly asks a sequence of questions of the form “Is your number greater than, equal to or less than X?” For various choices of X, and prints out the number.

  8. For example: >> binarySearch(1,63) is your number less, equal or greater than32?g is your number less, equal or greater than48?g is your number less, equal or greater than56?l is your number less, equal or greater than52?l is your number less, equal or greater than50?e s = Your number is50 We can implement such a function using the input statement: reply = input('Do you want more? Y/N [Y]: ', 's'); if isempty(reply) reply = 'Y'; end

  9. Warning: the code works fine for some values of such as n = 63, but may not work for other inputs, e.g. n = 64 The function is written as a recursive function.

  10. function out = binarySearch(L,R) % interactively guesses a number by binary search if L==R s = strcat('Your number is ', L) out = L; else mid = floor((L+R)/2); reply = input(strcat('is your number less, equal or ... greater than ', num2str(mid), ‘ ?'), 's'); if isempty(reply) 'equal, less or greater are the options' out = binarySearch(L,R); elseif strcmpi(reply, 'equal') || strcmpi(reply, 'eq') || strcmpi(reply, 'e') s = strcat('Your number is ', num2str(mid)) out = mid; elseif strcmpi(reply, 'less') || strcmpi(reply, 'le') || strcmpi(reply, 'l') out = binarySearch(L, mid-1); elseif strcmpi(reply, 'greater') || strcmpi(reply, 'gr') || strcmpi(reply, 'g') out = binarySearch(mid+1, R); else 'equal, less or greater are the options' out = binarySearch(L,R); end; end;

  11. User interface design example* We want to design a calculator with only one function, say addition. The inputs are entered in text boxes and when the Add! Button is pressed, the sum is displayed on the screen. (*Thanks to Quan Quach for the tutorial and the web site.)

  12. Creating components through UI We create the user interface through a “master” UI that has been implemented in Matlab. >> guide will give a template in which we can add various components and change their properties through property editor. We will walk through the tutorial in: http://blinkdagger.com/matlab/matlab-gui-graphical-user-interface-tutorial-for-beginners/

  13. The video clip in the following link http://www.mathworks.com/products/matlab/demos.html Shows how to build a fairly complex GUI. We can learn by experimenting with it.

More Related