Chapter 8. Data Structure: A variable that stores more than one value Matrices/vectors and character arrays are types of data structures MATLAB also provides.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Introduction to C Programming
Disk Storage, Basic File Structures, and Hashing
C++ crash course Class 10 practice problems. Pointers The following function is trying to swap the contents of two variables. Why isnt it working? void.
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Arrays, A1 COMP 401, Fall 2014 Lecture 4 8/28/2014.
Programming Environment S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Cells and Structures.
Chapter 10 Introduction to Arrays
CMPS 1371 Introduction to Computing for Engineers STRUCTURE ARRAYS.
Arrays  An array is a collection of like elements.  There are many engineering applications that use arrays.  MATLAB ® stores data in arrays and performs.
Chapter 7. Even in quantitative sciences, we often encounter letters and/or words that must be processed by code You may want to write code that: Reads.
Dale/Weems/Headington
 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 14, 2005.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Cells and Structures Array Cells and Array Structures.
Chapter 9: Arrays and Strings
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Cells and Structures Array Cells and Array Structures.
MATLAB Cell Arrays Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
Chapter 8 Arrays and Strings
CSE202: Lecture 16The Ohio State University1 Two Dimensional Arrays.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB
COMP 14 Introduction to Programming Miguel A. Otaduy June 1, 2004.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Chapter 9 Above: An early computer input/output device on the IBM 7030 (STRETCH)
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week2: Data Structure, Types and Manipulation in R.
Computer Science 121 Scientific Computing Winter 2014 Chapter 4 Collections and Indexing.
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Chapter 8 Arrays and Strings
Computer Science 210 Computer Organization Arrays.
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Defining a 2d Array A 2d array implements a MATRIX. Example: #define NUMROWS 5 #define NUMCOLS 10 int arr[NUMROWS][NUMCOLS];
Chapter 11 Hash Tables © John Urrutia 2014, All Rights Reserved1.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from
Cell Arrays: An Introduction Without an understanding of how cell arrays work and how to interact with them, cell arrays can be one of the most frustrating.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
1 Arrays Chapter 8. Objectives You will be able to Use arrays in your Java programs to hold a large number of data items of the same type. Initialize.
Arrays. Arrays are objects that help us organize large amounts of information.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Fundamentals of Programming Most.
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Foundations of Programming: Arrays
EGR 115 Introduction to Computing for Engineers
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Cell Arrays Definition Creating Cell Arrays Referencing Cell Arrays
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
Computer Science 210 Computer Organization
Topics Introduction to File Input and Output
Learning Plan 5 Arrays.
EECE.2160 ECE Application Programming
Presentation transcript:

Chapter 8

Data Structure: A variable that stores more than one value Matrices/vectors and character arrays are types of data structures MATLAB also provides two other types of data structures Cell Array Stores values of different types. Values can be strings, chars, doubles, matrices, etc… Numerically Indexed (so you can loop through them) Structure Stores values of different types Values can be can be strings, chars, doubles, matrices, etc… Values are stored in “fields” (i.e. you can’t loop through them) Useful for making databases

Up until now we have mainly focused on what matrices and character arrays can do Some General Rules… Must have consistent #cols Can’t have empty entries Can’t mix variables of different type i.e. you can’t mix doubles, ints, and chars

Advanced National Seismic System (ANSS) Near real-time data for all global earthquake events! Not just numbersNot just numbers USGS Current Water Data Near real-time data for streams in all 50 states! Not just numbersNot just numbers

What if you wanted to make a data structure that could hold anything of any size? (assuming you have sufficient RAM) Matrices Must have consistent dimensions Must have consistent dimensions Must be all numeric (no chars/strings) Must be all numeric (no chars/strings) Character Arrays (Strings) Must have consistent dimensions (of characters) Must have consistent dimensions (of characters) Must contain only characters Must contain only charactersMatrices Must have consistent dimensions Must have consistent dimensions Must be all numeric (no chars/strings) Must be all numeric (no chars/strings) Character Arrays (Strings) Must have consistent dimensions (of characters) Must have consistent dimensions (of characters) Must contain only characters Must contain only characters Cell Arrays An array of cells An array of cells Each cell can hold anything Each cell can hold anything char, double, int, matrix, vector, string, logicalchar, double, int, matrix, vector, string, logical Each entry can be any sizeEach entry can be any size Unlike matrices, a given cell can be emptyUnlike matrices, a given cell can be empty Technically, the cell doesn’t hold the value, it just contains a pointer to where the contents are stored. Technically, the cell doesn’t hold the value, it just contains a pointer to where the contents are stored. This usually isn’t important for us as Earth scientists.This usually isn’t important for us as Earth scientists. Cell Arrays An array of cells An array of cells Each cell can hold anything Each cell can hold anything char, double, int, matrix, vector, string, logicalchar, double, int, matrix, vector, string, logical Each entry can be any sizeEach entry can be any size Unlike matrices, a given cell can be emptyUnlike matrices, a given cell can be empty Technically, the cell doesn’t hold the value, it just contains a pointer to where the contents are stored. Technically, the cell doesn’t hold the value, it just contains a pointer to where the contents are stored. This usually isn’t important for us as Earth scientists.This usually isn’t important for us as Earth scientists.

How do I create a cell array? Cell arrays are created using curly braces { } Follow the same indexing rules as matrices If you use (), this is called cell indexing Returns the cell (not the contents) of the specified index

How do I create a cell array? Cell arrays are created using curly braces { } To get a cell’s contents use curly braces { } Called content indexing Returns the cell’s contents of the specified index Typically, a string, some numeric value, or matrix

How do I pre-allocate a cell array? Use ‘cell(m,n)’ Makes an empty m x n cell array You can later add in the cell contents Essentially the same as pre- allocating a matrix, except cells can be empty Why should I do this? Cell arrays suffer from the same inefficiencies as matrices, so they should be pre-allocated whenever possible This mainly applies to adding in cells in a loop

Referring to the contents of a cell may look intimidating But it makes sense! Because cell arrays are numerically indexed Can use loops to go through entries

Cell Arrays are a little confusing at first, but they are necessary so we can… Mix strings of different lengths in a single variable Mix numbers, matrices, vectors, strings, characters in a single variable Cell arrays are most commonly used in two situations: You want to store a list of words that are different lengths You want to read in a data file that has both numbers and words/letters For this, we need to move onto “Advanced File I/O”