Cells and Structures Array Cells and Array Structures.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Arrays.
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.
Arrays, A1 COMP 401, Fall 2014 Lecture 4 8/28/2014.
Variables i)Numeric Variable ii)String Variable
Names and Bindings.
CMPS 1371 Introduction to Computing for Engineers STRUCTURE ARRAYS.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
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 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Chapter 10.
Arrays Liang, Chpt 5. arrays Fintan Array of chars For example, a String variable contains an array of characters: An array is a data structure.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
Java Syntax Primitive data types Operators Control statements.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Cells and Structures Array Cells and Array Structures.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MATLAB Cell Arrays Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
Java Unit 9: Arrays Declaring and Processing Arrays.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Lists in Python.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Chapter 2 Numeric, Cell, and Structure Arrays. Physics Connection - Specification of a position vector using Cartesian coordinates. Figure 2.1–1 2-2 The.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
1 Data Structures CSCI 132, Spring 2014 Lecture 10 Dynamic Memory and Pointers.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Working with Arrays in MATLAB
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Pointers *, &, array similarities, functions, sizeof.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
1 CS 101 Fall 2001 Lecture 3. 2 Boolean expressions The expressions that are allowed to be in the parentheses following an if can be of the form x>y,
Arrays.
COMPUTER PROGRAMMING. Array C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
Compiler Design Lecture 10 Semantic Analysis. int aintegers int a[2][3]array(2, array(3, integer)) int f(int, float, char) int x float x char  int Int.
Relational and Logical Operators EE 201 1C7-2 Spring 2012.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Compiler Design Lecture 10 Semantic Analysis. int aintegers int a[2][3]array(2, array(3, integer)) int f(int, float, char) int x float x char  int Int.
Arrays and Pointers (part 1) CSE 2031 Fall July 2016.
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Chapter 2: Introduction to C++
Introduction to MATLAB 7
Other Kinds of Arrays Chapter 11
EKT150 : Computer Programming
Data Types and Data Structures
INTRODUCTION TO MATLAB
PROGRAMMING IN HASKELL
Chapter 2: Introduction to C++.
JavaScript.
Weighted Mean.
Introduction to MATLAB 7
Working with Arrays in MATLAB
Presentation transcript:

Cells and Structures Array Cells and Array Structures

Character Strings planets=['Mercury','Venus','Earth'] Matlab returns one concatenated character string MercuryVenusEarth planets(1) is therefore only the first character, that is 'M' Planets={'Mercury','Venus','Earth'} Matlab now returns 3 separate character strings 'Mercury' 'Venus' 'Earth' Planets(1) is now 'Mercury' Planets{1} is then Mercury without the quotes

Array of one dimensional cells ['Mercury' ; 'Venus' ; 'Earth'] would avoid the catenation, but it is illegal since the three strings are not of equal length. (It is also inefficient.) {'Mercury','Venus','Earth'} is a one dimensional cell array Content of each cell can be of different type p={'Mars', 3.7, '2005', 2005} but if they are different accessing the cells becomes difficult Note p{3} and p{4} are different – see 5*p{3} and 5*p{4} Use structures instead – see later

Creating Cell Arrays A = cell(2) creates a 2 by 2 array for cells Each cell can have a different content Note how content of a cell has be enclosed in curly brackets A(1,1) = {'ENDF 121'} A(1,2) = {'Fall 2005'} A(2,1) = { [1:7] } A(2,2) = { [22,15,22,23,24,25,21] }

Different way of accessing cells via 'content indexing' B = cell(2,3) creates a 2 by 3 array whose cells are accessed by using {, } for the indices instead of (, ) B{1,1} = 'special matrices' B{1,2} = zeros(3) B{1,3} = ones(3) B{2,1} = 'their inverse' B{2,2} = 'does not exist' B{2,3} = ones(3)

Creating cell arrays It is not necessary to use the cell function first but if variable exists already an error will occur Can use clear to avoid this problem cells can be multi dimensional, i.e. m = cell( 2,3,4,2 ) cells can be nested, i.e. a single cell element can reference another cell Note difference between cell indexing A(1,1) = {' This class '} and content indexing A{1,1} = 'This class' and direct addressing A(1,1) = 123; in the last case the floating point number 123 is stored directly at the storage location associate with A(1,1). the last case can not be mixed with the first two

Functions for working with cells C = cell(m,n,p,…) celldisp(C) cellplot(C) C = num2cell(A) A numeric array – uses direct addressing C array of cells – uses indirect addressing iscell(C) returns 1 for true 0 for false [X,Y,…] = deal(A,B,…) same as X=A; Y=B; … number of variables have to be the same on both sides except for special case [X,Y,…] = deal(A)

Example for students in class S{1,1} = 'Joe Smith' S{1,2} = ' ' S{1,3} = S{1,4} = [67,78,45] ; S{2,1} = 'Ann Schmidt' S{2,2} = ' ' S{2,3} = S{2,4} = [78,95,67] ;

Difficulties with cells Cells of previous example hold information in following order (second index) 1. name 2. social security number 3. address 4. scores for tests First index refers to student number in class When entering data need to remember all of this Excel or Access or similar programs are a much better choice for this type of problem Cells are useful for annotating graphs, identifying data, etc.