L21post - Previous Lecture: Working with large data files...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
± Previous Lecture: ± Working with large data files ± Today’s Lecture: ± A data file example; built-in sort function ± Review matrix, cell array, structure array ± Announcement: ± Section in classrooms this week ± Prelim 2 tonight at 7:30pm ± Lastnames A - I: Hollister B14 ± Lastnames J - P: Kimball B11 ± Lastnames Q - Z: Upson B17
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 10, 2009 Lecture 21 2 A detailed sort-a-file example Suppose each line in the file statePop.txt is structured as follows: Cols 1-14: State name Cols 16-24: Population (millions) The states appear in alphabetical order.
Background image of page 2
November 10, 2009 Lecture 21 3 Alabama 4557808 Alaska 663661 Arizona 5939292 Arkansas 2779154 California 36132147 Colorado 4665177 : : : : Texas 22859968 Utah 2469585 Vermont 623050 Virginia 7567465 Washington 6287759 West Virginia 1816856 Wisconsin 5536201 Wyoming 509294
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 10, 2009 Lecture 21 4 A detailed sort-a-file example Create a new file statePopSm2Lg.txt that is structured the same as statePop.txt except that the states are ordered from smallest to largest according to population. • Need the pop as numbers for sorting. • Can’t just sort the pop— have to maintain association with the state names. Alabama 4557808 Alaska 663661 Arizona 5939292 Arkansas 2779154 California 36132147 Colorado 4665177 : : : :
Background image of page 4
November 10, 2009 Lecture 21 5 First, get the populations into an array C = file2cellArray('StatePop'); n = length(C); pop = zeros(n,1); for i=1:n S = C{i}; pop(i) = str2double(S(16:24)); end
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 10, 2009 Lecture 21 6 Built-In function sort Syntax: [y,idx] = sort(x) 10 20 5 90 15 5 10 15 20 90 3 1 5 2 4 X: y: idx: y(1) = x(3) = x(idx(1))
Background image of page 6
November 10, 2009 Lecture 21 7 Built-In function sort Syntax: [y,idx] = sort(x) 10 20 5 90 15 5 10 15 20 90 3 1 5 2 4 X: y: idx: y(2) = x(1) = x(idx(2))
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 10, 2009 Lecture 21 8 Built-In function sort Syntax: [y,idx] = sort(x) 10 20 5 90 15 5 10 15 20 90 3 1 5 2 4 X: y: idx: y(3) = x(5) = x(idx(3))
Background image of page 8
November 10, 2009 Lecture 21 9 Built-In function sort Syntax: [y,idx] = sort(x) 10 20 5 90 15 5 10 15 20 90 3 1 5 2 4 X: y: idx: y(4) = x(2) = x(idx(4))
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 10, 2009 Lecture 21 10 Built-In function sort Syntax: [y,idx] = sort(x) 10 20 5 90 15 5 10 15 20 90 3 1 5 2 4 X: y: idx: y(5) = x(4) = x(idx(5))
Background image of page 10
November 10, 2009 Lecture 21 11 Built-In function sort Syntax: [y,idx] = sort(x) 10 20 5 90 15 5 10 15 20 90 3 1 5 2 4 X: y: idx: y(k) = x(idx(k))
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 10, 2009 Lecture 21 12
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

L21post - Previous Lecture: Working with large data files...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online