Class Notes (808,384)
United States (313,087)
ENG 6 (40)
Lecture 14

# ENG 06: Engineering Problem Solving with MATLAB – Lecture 14 notes

4 Pages
45 Views

School
University of California - Davis
Department
Engineering
Course
ENG 6
Professor
Professor Rajeevan Amirtharajah
Semester
Spring

Description
ENG 06 – Lecture 14; 2/21/2013 Graphical User Interfaces – GUIs  All project options involve designing a GUI  Event driven, not sequential  Properties of Objects o Edit using interactive interface o Edit code directly o Refer to objects with tags  Stored in structure called handles, use handles to call objects o Matlab will automatically generate code for GUI after using interactive interface  Functions for Programming a GUI o Example: make a program called adding.m  Has two editable text boxes – edit1 and edit2  Has a button, pushbutton1  Function pushbutton1_Callback is run when pushbutton1 is clicked o Want to add numbers in edit1 and edit2 when button is clicked, then display in text2 ( a static, noneditable text box):  function pushbutton1_Callback(hObject, eventdata, handles)  a = get(handles.edit1,'String');   b = get(handles.edit2,'String');   c = str2num(a) + str2num(b);  set(handles.text2,'String',num2str(c)); o note: need to convert from strings to numbers then back again (can’t add strings) Character Strings  matlab has functions that simplify string manipulation  Concept: Mapping o Defines relationship btwn two entities  Ex. between a function value and independent variable o Character mapping allows each character to be uniquely represented by numerical value  This is how computer treats characters  Created by a character generator from numerical code  256 integer numbers (2^8, 256 8-bit binary numbers) o Numerical values are stored in MATLAB in special internal representation o Internal representation is converted into character string o To enter numerical string, create a character string and convert it to internal representation  Concept: Casting o Changing way a language views a piece of data w/out changing value o Sometimes we want to force the language to treat a data item in a specific way o Matlab implements casting as a function w/ name of data type  Implementation of casting o uint8(‘A’) o ans = 65  uint8 is an integer data type, values 0-255  coverts elements of array into unsigned 8-bit integers o char(100) o ans = d  char is character class o char([97 98 99 100 101]) o ans = abcde  converts array w/ nonnegative integers into MATLAB character array o class command tells you what class a character is  char = string  double = number  String Operations o Since strings are vectors of numbers, all normal vector operations apply  Arithmetic and logical operations  Concatenation  Shortening  Indexing  Slicing  String Comparisons o Must obey vector comparison rules o DO NOT DO THIS:  >> ‘abcd’==’abcd’  ans = 1111  >>’abcd’==’abcde’  error- array dimensions must match o Use either strcmp or strcmpi  Strcmp is case sensitive  Strcmpi is case insensitive o You can use strings of any length o Returns a single logical value, 0 or 1, which refers to full vector o Example:  >>thislecture = 'blah blah blah';   >> if(strcmp(thislecture,'brilliant insights'))  disp('job well done')  else   disp(‘waste of tuition money’)  end   waste of tuition money  Arrays of Strings o Can be constructed as a vertical vector of strings, all must be the sa
More Less

Related notes for ENG 6

OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.