L16. Cell Arrays Set-Up Subscripting Nested Loops String Manipulations.

Slides:



Advertisements
Similar presentations
“God Is Not…” “God is not a man” Numbers 23:19 God’s dependable nature
Advertisements

4.1- Plot Points in a Coordinate Plane
Advanced Piloting Cruise Plot.
Probability and Conditional Probability. Probability Four balls What is the probability of choosing the ball in the red box? Since there are four balls.
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Roman Numerals.
1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure Definitions 10.3Initializing Structures 10.4Accessing.
StructuresStructures Systems Programming. Systems Programming: Structures 2 Systems Programming: 2 StructuresStructures Structures Structures Typedef.
Con Law Card Answers.
StructuresStructures Systems Programming. StructuresStructures Structures Structures Typedef Typedef Declarations Declarations Using Structures with Functions.
1 CSC 221: Introduction to Programming Fall 2011 List comprehensions & objects building strings & lists comprehensions conditional comprehensions example:
2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
Case Study: Focus on Structures Math 130 Lecture 21 B Smith: 10/04: Required 35 minutes to complete. 15 minutes was spent returning test 2 and completing.
2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Structures –Collections of related.
2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
1 Structures. 2 Structure Basics A structure is a collection of data values, called data members, that form a single unit. Unlike arrays, the data members.
1 Structures. 2 Structure Basics A structure is a collection of data values, called data members, that form a single unit. Unlike arrays, the data members.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Bits, Characters, Strings, and Structures Outline 16.1Introduction 16.2Structure Definitions.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
15.7 Probability Day 3. There are 2 nickels, 3 dimes, and 5 quarters 1.) Find the probability of selecting 1 nickel, 1 dime, and 1 quarter in that order.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Structures Functions and Arrays Dale Roberts, Lecturer Computer.
O X Click on Number next to person for a question.
Properties of Exponents
Moses & The Rock A.Romans 15:4 B.Numbers 20:1-13.
“Be An Example” Introduction 1st Timothy 4:12 Matthew 5:16
Addition 1’s to 20.
Test B, 100 Subtraction Facts
Week 1.
Counting Techniques 1. Sequential Counting Principle Section
Quit Introduction Cards Combining Probabilities.
O X Click on Number next to person for a question.
Index Student Activity 1: Questions to familiarise students with the
Boost Spirit V2 A cookbook style guide to parsing and output generation in C++ Joel de Guzman Hartmut Kaiser
1 Ancient Numeration Systems Thank you Dr. Wyatt.
Insight Through Computing 16. Cell Arrays Set-Up Subscripting Nested Loops String Manipulations.
Lecture 7 C Pointers Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.

Roman Numerals. Roman Numerals - Past and Present  Romans used them for trading and commerce.  When Romans learned to write they needed a way to write.
Roman Numerals. The Numbers I-1 II-2 III-3 IV-4 V-5 VI-6 VII-7 VIII-8 IX-9 X-10 C-100 D-500 M-1000.
By.. Miss Prangtip Kaewsuphot
Roman Numerals This is the entrance to the Colosseum in Rome.
Roman Numerals Learning objective: To learn how to count using Roman numerals.
1 EPSII 59:006 Spring Exam Dates 3 Homework Grading In general, programs that do not compile and run will be given no more than 25% credit Points.
JavaScript: The First Parts Part Three Douglas Crockford Yahoo! Inc.
An outline is useful to organize your information You put this information in categories You use various symbols to organize your information For main.
¸üµÖŸÖ ×¿ÖÖÖ ÃÖÓãÖÖ,ÃÖÖ ŸÖÖ¸üÖ ú´ÖÔ¾Ö߸ü ×¾ÖªÖ¯ÖϲÖÖê× ¬Ö­Öß, ´Ö¬µÖ ×¾Ö³Ö֐Ö, ÃÖÖŸÖÖ¸üÖ ¿ÖÖ»ÖêµÖ †³µÖÖÃ֍Îú´ÖÖ­ÖãÃÖÖ¸ ÃÖÓãÖêŸÖᯙ ÃÖê¾ÖúÖÓ­Öß ŸÖµÖÖ¸ü.
Introduction to the new Mathematics Primary Curriculum Spring 2014.
Maths in Year 3 at St Anselm’s.
Parents Guide to Calculation
Plenary: rules of indices
Roman Numerals Adding value to letters I, V, X, L, C, D, M 11/30/2018.
Roman Numerals.
Write these notes in your spirals!
Roman Numerals Used for some drugs and solutions, and used at times while ordering supplies Key symbols: I, V, X, L, C, D, M Arabic Roman.
Index Notation Sunday, 24 February 2019.
Roman Numerals.
Roman Numerals.
Roman Numerals.
Roman numerals -Rules for writing.
Roman Numerals.
Roman Numerals.
Presentation transcript:

L16. Cell Arrays Set-Up Subscripting Nested Loops String Manipulations

A Small Cell Array… C = { Alabama,New York,Utah}; C: Alabama New York Utah

Syntax C = { Alabama,New York,Utah}; Curly Brackets Entries Separated by Commas

Synonym C = { Alabama,New York,Utah}; C = cell(1,3); C{1} = Alabama; C{2} = New York; C{3} = Utah; Application: Storing strings

Vertical Cell Array Set-up C = { Alabama;New York;Utah}; C = cell(3,1); C{1} = Alabama; C{2} = New York; C{3} = Utah; Application: Storing strings

Another Small Cell Array… C = { [1 2 3],[10;20], zeros(1,4)}; C: [1 2 3] [10;20] zeros(1,4)

Syntax C = { [1 2 3], [10;20], zeros(1,4)}; Curly Brackets Entries Separated by Commas

Synonym C = cell(1,3); C{1} = [1 2 3]; C{2} = [10;20]; C{3} = zeros(1,4); Application: Storing a Set of Arrays C = { [1 2 3], [10;20], zeros(1,4)};

Problem: Set Up a Card Deck

Idea… A{1} = A Hearts; A{2} = 2 Hearts; : A{13} = K Hearts; A{14} = A Clubs; : A{52} = K Diamonds;

Initializations… suit = {Hearts, Clubs, … Spades, Diamonds}; rank = {A,2,3,4,5,6,… 7,8,9,10,J,Q,K}; A = cell(1,52);

Use Concatenation… suit = {Hearts, Clubs, … Spades, Diamonds}; rank = {A,2,3,4,5,6,… 7,8,9,10,J,Q,K}; A{16} = [rank{3} suit{2} ] A{16} = 3 Clubs

Nested Loop to Get all Possible Combinations… % i is index of next card… i = 1; for k=1:4 % Set up the cards in suit k for j=1:13 A{i} = [ rank{j} ' ' suit{k} ]; i = i+1 end

Problem: Deal a Card Deck

Deal a length-12 Card Deck N: 1,5,9 E: 2,6,10 S: 3,7,11 W: 4,8,12 A: 4k-3 4k-2 4k-1 4k

N = cell(1,13); E = cell(1,13); S = cell(1,13); W = cell(1,13); for k=1:13 N{k} = A{4*k-3}; E{k} = A{4*k-2}; S{k} = A{4*k-1}; W{k} = A{4*k}; end

Problem: Shuffle a Card Deck

Shuffle a length-12 Card Deck AB L CDEFGH IJ K

Step 1: Cut the Deck AB L CDEFGH IJ K ABCDEF L GH IJ K

Step 2: Alternate AB L CDEFGH IJ K ABCDEF L GH IJ K AG L BHCIDJ EK F

Step 2: Alternate AB L CDEFGH IJ K ABCDEF L GH IJ K AG L BHCIDJ EK F k -> 2k-1

Step 2: Alternate AB L CDEFGH IJ K ABCDEF L GH IJ K AG L BHCIDJ EK F k -> 2k

function T = Shuffle(S) n = length(S); m = n/2; T = cell(n,1); Top = S(1:m); Bot = S(m+1:n); for k=1:m T{2*k-1} = Top{k}; T{2*k} = Bot{k}; end

8 Shuffles with a Card Deck… And you are back where you started.

% Set up a 52-color spectrum C = cell(52,1); for k=1:52 f = (k-1)/51; C{k} = [f 0 1-f]; end Illustrate with Color These are colors

Using fill(,, C{k})…

Problem: Build Cell Array of Roman Numerals

C{1} = I C{2} = II C{3} = III : C{2007} = MMVII : C{3999} = MMMXMXCIX Idea…

A Conversion Problem 1904 = 1* * *10 + 4*1 = M CM IV

1904 MCMIV

1904 M || CM || || IV

M MM MMM 1904 M || CM || || IV

C CC CCC CD D DC DCC DCCC CM M MM MMM 1904 M || CM || || IV

C CC CCC CD D DC DCC DCCC CM X XX XXX XL L LX LXX LXXX XC M MM MMM 1904 M || CM || || IV

C CC CCC CD D DC DCC DCCC CM X XX XXX XL L LX LXX LXXX XC I II III IV V VI VII VIII IX M MM MMM 1904 M || CM || || IV Concatenate entries from these cell arrays

Ones-Place Conversion function r = Ones2R(x) % x is an integer that satisfies % 0 <= x <= 9 % r is the Roman numeral with value x. Ones = {'I', 'II', 'III', 'IV',… 'V', 'VI','VII', 'VIII', 'IX'}; if x==0 r = ''; else r = Ones{x}; end

Tens-Place Conversion function r = Tens2R(x) % x is an integer that satisfies % 0 <= x <= 9 % r is the Roman numeral with value 10x. Tens = {X', XX', XXX', XL',… L', LX',LXX', LXXX', XC'}; if x==0 r = ''; else r = Tens{x}; end

Hundreds-Place Conversion function r = Hund2R(x) % d is an integer that satisfies % 0 <= x <= 9 % r is the Roman numeral with value 100x. Hund = {C', CC', CCC', CD',… D', DC',DCC', DCCC', CM'}; if x==0 r = ''; else r = Hund{x}; end

Thousands-Place Conversion function r = Thou2R(x) % d is an integer that satisfies % 0 <= x <=3 % r is the Roman numeral with value 1000x. Thou = {M', MM', MMM'}; if x==0 r = ''; else r = Thou{x}; end

C{1} = I C{2} = II C{3} = III : C{2007} = MMVII : C{3999} = MMMXMXCIX Back to Our Problem

Generate 1,…,3999 a b c d 0 <= a <= 3 0 <= b <= 9 0 <= c <= 9 0 <= d <= 9

for a = 0:3 for b = 0:9 for c = 0:9 for d = 0:9 n = a* b*100 + c*10 + d end This Prints 0,…,3999

n = a* b*100 + c*10 + d; if n > 0 C{n} = [Thou(a) Hund(b)… Tens(c) Ones(d)]; end

Reverse Problem Given Roman Numeral, compute its value. Assume cell array C(3999,1) available: C{1} = I : C{3999} = MMMCMXCIX

function k = RN2Int(r) % r is a string that represents % Roman numeral % k is its value C = RomanNum; k=1; while ~strcmp(r,C{k}) k=k+1; end