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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

COMP 116: Introduction to Scientific Programming Lecture 37: Final Review.
Introduction To MATLAB Programming
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Strings.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Additional Data Types: 2-D Arrays, Logical Arrays, Strings Selim Aksoy Bilkent University Department of Computer Engineering
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering
Lecture 3 August 31 Chapter 3. Chapter 3 – numbers, string, booleans integer: MATLAB stores numeric data as double-precision floating point (double) by.
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Additional Data Types: Strings Selim Aksoy Bilkent University Department of Computer Engineering
MATLAB Strings Selim Aksoy Bilkent University Department of Computer Engineering
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)
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
AN ENGINEER’S GUIDE TO MATLAB
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Text Processing. Outline Announcements: –Homework I: due Today. by 5, by Discuss on Friday. –Homework II: on web HW I: question 7 Finish functions.
GUI Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
CSE123 Lecture 6 String Arrays. Character Strings In Matlab, text is referred to as character strings. String Construction Character strings in Matlab.
Chapter 5 Selected Single-Row Functions. Chapter Objectives  Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
COMP 116: Introduction to Scientific Programming Lecture 24: Strings in MATLAB.
File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.
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.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
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.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
COIT29222-Structured Programming Lecture Week 08  Reading: Textbook (4 th Ed.), Chapter 4 Textbook (6 th Ed.), Chapter 7 Study Guide Book 2, Module 11.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
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.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
Introduction to Matlab Module #8 Page 1 Introduction to Matlab Module #8 – Animation Topics 1.getframe 2.pause 3.Plotting a set of files Textbook Reading.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
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.
An Introduction to Programming in Matlab Emily Blumenthal
Characters and Text You can assign text strings to MATLAB variables using single quotes. For example, c = 'Hello'; The result is not a numeric matrix or.
Input/Output Functions. 2 MATLAB Basics: Data Files save filename var1 var2 … save homework.mat x y  binary save x.dat x – ascii  ascii load filename.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
INC 161 , CPE 100 Computer Programming
C Characters and Strings
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Characters and Text You can assign text strings to MATLAB variables using single quotes. For example, c = 'Hello'; The result is not a numeric matrix or.
String Manipulation Chapter 7 Attaway MATLAB 4E.
Beginning C for Engineers
functions: argument, return value
Text functions.
Character Arrays.
CS 111 Introduction to Computing in Engineering and Science
Text Manipulation Chapter 7 Attaway MATLAB 5E.
C Characters and Strings
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

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 data files that contain both numbers and words Writes data to files (filenames are strings) Read a list of files Combine a string and a number Label plot titles or axes with nums and words Prints messages with words and numbers mixed

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

Recall that strings are arrays of characters i.e. a matrix of characters

Strings can form rectangular matrices too! Must follow same matrix rules Rows and Cols must be consistent

Strings can form rectangular matrices too! Must follow same matrix rules Rows and Cols must be consistent Can “pad” each row with blank spaces to make columns consistent You can read about “strcat”, “srtvcat”, and “char”

What if you want to combine a numeric result with a word? fprintf: only prints to the command window (can’t store/use the result) sprintf: works just like fprintf, but makes a string

What if you want to label a plot with numbers from data? Most MATLAB commands for labeling only accept strings Use sprintf to make a string with text+number. Then use the string

What if you want to label a plot with numbers from data? Most MATLAB commands for labeling only accept strings Use sprintf to make a string with text+number. Then use the string

Attaway also covers deblank char strtrim upper lower These may come in handy someday You can read about these functions for their usage

What if you want to see if two strings are identical? Do not use “==“ Compares ASCII values May work, but is bad programming style, and can produce unwanted results Use “strcmp” or “strncmp” Compares strings

What if you want to see if two strings are identical? strcmp compares two strings returns logical true if identical strncmp compares the first n characters of two strings Returns logical true if identical You can read about “strfind”, “findstr”, “strrep”, and “strtok”.

Now that you know about various variable types in MATLAB… May want to test whether a variable contains a certain type of data Various “is” functions do this ischar isletter isspace

int2str Converts an int to a string Automatically rounds off if needed num2str Converts an number (double or int) to a string Can specify precision If precision not specified, uses current MATLAB defaults

str2num Converts a string to a number (double)

What if you have a bunch of files that you want to load? Don’t load each one, one by one by hand Waste of time! Knowledge of string processing can help! Use “ls” as a function Store result as character array

Fair Warning: Data files are read in the order that ls reports. If not in order, you will have to sort the data.