12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

t = {’help’ spiral(3) ; eye(2) ’I’’m stuck’};>> tt = {t t ;t’ fliplr(t)};>> tt{2,2}{2,1}(5:9)ans =stuck28 StructuresStructures are arrays whose names have dot-separated parts. They canbe used to store information <strong>of</strong> different kinds together in a hierarchicalstructure. Let us do a simple example:>> staff.name = ’John Smith’staff =name: ’John Smith’>> staff.age = 43staff =name: ’John Smith’age: 43>> staff.favourites = [1 42 37]staff =name: ’John Smith’age: 43favourites: [1 42 37]We have created a structure called staff which is <strong>of</strong> size 1 × 1:>> whosName Size Bytes Classstaff 1x1 424 struct arrayThe staff structure has three fields: name, age, <strong>and</strong> favourites:>> staffstaff =name: ’John Smith’age: 43favourites: [1 42 37]To add another staff member’s data to this structure, add subscripts todefine a second element:staff(2).name = ’Jane Smythe’;staff(2).age = 30;staff(2).favourites = [pi eps realmax realmin NaN Inf];The sizes <strong>of</strong> the fields do not have to be the same for each element <strong>of</strong> thestructure. For example, Jane Smythe’s favourite vector contains moreelements than John Smith’s.c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!