ENG 06: Engineering Problem Solving with MATLAB – Lecture 12 notes

3 Pages
Unlock Document

University of California - Davis
Professor Rajeevan Amirtharajah

ENG 06 – Lecture 12; 2/14/2013 Questions Task 1 -Is there a way to test your answer? Look in the spreadsheet -there is a unique function you can use to check it (help unique) Task 6 -use loop to display answer only task 19 how to convert to text file? Function – fopen (help fopen) to display table, use fprintf (everything is text characters) Structure Arrays and Cell Arrays  Usually want to use structures rather than cells o Code is easier to understand from outside perspective w/ structures  Can access objects in structure array by name; w/ cells you have to use indexing Constructing and Accessing a Structure  To set value of items in a structure A, use following syntax: o >>A.string = ‘abcde’ o A = o string: ‘abcde’ o >>A.number = 42 o A = o string:’abcde’ o Number:42  Fields in a structure are accessed in the same way, by using the dotted notation: o >>A.number = A.number./2 o A =  String:’abcde’  Number:21  Manipulating Field Names o Built in function fieldnames(…) returns cell array with field names as strings  >>names=fieldnames(A)  names=  ‘string’  ‘number’ o you can remove a field from a structure using rmfield(…)  returns new structure w/ field removed, but does not remove field from original structure  >>rmfield(a,’string’)  A = number:21 o If you want to remove the field, assign result to replace original structure  Accessing Fields in a Structure Array o Direct field addressing:  >>A.string = [A.string’fg’]  A =  String: ‘abcdefg’  Number:21  Needed to know name of first label (annoying) o Indirect Field Addressing  Sets variable to name of field  use parentheses to indicate that variable contents should be used as field name  >>names = fieldnames(A)  >>fn = names{1};  >>A.(fn) = [A.(fn) ‘fg’]  A =  String:’abcdefgfgfg’  Number: 21  All you need to know is that you want to manipulate the first fie
More Less

Related notes for ENG 6

Log In


Don't have an account?

Join OneClass

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

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.