Logical Ops on Arrays Saving time / avoiding loops 1. Logical Operators 2. Logical Operations 3. Examples: numbers and letters 11.

Slides:



Advertisements
Similar presentations
Introduction to MATLAB The language of Technical Computing.
Advertisements

Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
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.
MATLAB FUNDAMENTALS: INPUT/OUTPUT LOGIC CONTROL STRUCTURES HP 101 – MATLAB Wednesday, 9/24/2014
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Array Math.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
ARRAY REFERENCING 1 1. II. Array Referencing Assume an array has values. It is useful to “refer to” the elements contained within it – as smaller portions.
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
Logical Ops’ on Arrays When we need to compare arrays, find a number within an array, isolate all invalid numbers… 1. Logical Operators 2. Logical Operations.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Cell Arrays 1.Definition 2.Creating Cell Arrays 3.Referencing Cell Arrays 4.Augmenting Cell Arrays 5.Use of Cell Arrays 1.
File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Presenting results to the USER in a professional manner 1. semicolon, disp(), fprintf() 2. Placeholders 3. Special characters 4. Format-modifiers Output.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
File I/O 1. Goals of this chapter 2. General Concept, lots of examples 3. High-level I/O 1. Built-in functions that do everything in one step 4. Low-level.
Introduction to File I/O High-Level Functions 1.Data files 2."High level" File I/O 3.dlmread() 4.xlsread() 1.
1. Definition and General Structure 2. Small Example 1 3. Simplified Structure 4. Short Additional Examples 5. Full Example 2 6. Common Error The for loop.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
1 Chapter 3 Arrays (2) 1. Array Referencing 2. Common Operations 1. Slicing 2. Diminution 3. Augmentation 3. List of Commonly Used Built-in Functions 1.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system.
File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.
Built-in Data Structures in Python An Introduction.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
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.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Asking the USER for values to use in a software 1 Input.
Working with Arrays in MATLAB
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Microsoft® Excel Key and format dates and times. 1 Use Date & Time functions. 2 Use date and time arithmetic. 3 Use the IF function. 4 Create.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
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.
Asking the USER for values to use in a software 1 Input.
Digital Image Processing Introduction to M-function Programming.
Lecture 6: Output 1.Presenting results in a professional manner 2.semicolon, disp(), fprintf() 3.Placeholders 4.Special characters 5.Format-modifiers 1.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Early File I/O To help you get started with your final project 1. Definition of “high level” 2. Is using a High Level function appropriate? 3. xlsread()
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
FILE I/O: Low-level 1. The Big Picture 2 Low-Level, cont. Some files are mixed format that are not readable by high- level functions such as xlsread()
MATLAB: Structures and File I/O
Advanced Data Import & Export Jeff Henrikson
Matlab Basics.
Presentation transcript:

Logical Ops on Arrays Saving time / avoiding loops 1. Logical Operators 2. Logical Operations 3. Examples: numbers and letters 11

General Idea Applied to arrays, this solves problems such as… Find where the positives are positioned Count the number of negatives Delete the negatives, or maybe replace them by zeros Replace letters by other letters In MATLAB, these can easily be solved in 1 or 2 lines, without the use of any loop and if statement (necessary in Java, C, C++..) This is very useful in engineering, as tables of data always have to be filtered before use! Note this is UNIQUE to MATLAB. No other software out there does this, so learn your loops and if statements anyway…. 2

General Idea Suppose an array of values (vector or matrix) exists. The values came from sensors on a rocket, on a robot, on a car, etc How many sensors gave negative values? 3 2. Which sensors returned negative values? #1 #5# What were the actual negative values?

General Idea Suppose a document with letters, words and sentences. (An array of letters). 1. How many capital letters are there? 2. Extract the capital letters, keep them in order. 3. At what positions are the capital letters located? 4. Encrypt the document by changing all a's to z's? 4

General Idea Recall the relational and logical operators ( > >= < <= ~= == && || ) 5

General Idea Recall the relational and logical operators ( > >= < <= ~= == && || ) Logical Operations return a: true – this can be evaluated as 1 false – this can be evaluated as 0 6

General Idea Recall the relational and logical operators ( > >= < <= ~= == && || ) Logical Operations return a: true – this can be evaluated as 1 false – this can be evaluated as 0 2>5 is false, and can be evaluated as 0 2==4 is false, and can be evaluated as 0 6>=0 is true, and can be evaluated as 1 7

General Idea Recall the relational and logical operators ( > >= < <= ~= == && || ) Logical Operations return a: true – this can be evaluated as 1 false – this can be evaluated as 0 2>5 is false, and can be evaluated as 0 2==4 is false, and can be evaluated as 0 6>=0 is true, and can be evaluated as 1 X=4 %X is a scalar 0<=X && mod(X,2)==0 %positive and even is ______, and can be evaluated as __ 8

General Idea Recall the relational and logical operators ( > >= < <= ~= == && || ) Logical Operations return a: true – this can be evaluated as 1 false – this can be evaluated as 0 X= [ … ]; %X is a not a scalar 0<=X & mod(X,2)==0 %positive and even 9 In this section on arrays, only type 1 symbol: &, or | “element-wise” AND, OR

Logical Operations 1. Suppose we want to know how many sensors gave negative values… What operation can be done to count the number of negatives? ________ 10 When MATLAB applies an operation to each element in an array, we say that it is a “vector operation”. Here, MATLAB evaluates the condition on each element and assigns a 1 when true, a 0 when false. This creates a “logical vector”

Logical Operations, cont. 11 Simply use the built-in function. 1. How many sensors gave negative values?

Logical Operations, cont. 12 negatives is a logical vector. negatives is also called a 'mask'. 1. How many sensors gave negative values?

Logical Operations 13 How do we get the actual sensor numbers: #1 and #4? 2. Which sensors returned negative values?

Logical Operations, cont. MATLAB offers a built-in function that find s the index of values that make a condition true. In this application, “find where the sensor values are negatives”. 14 whereNegatives is a vector of indices

Logical Operations What were the actual negative values? What are the actual values located at positions 1 and 4?

Logical Operations 16 3 methods possible: 1. Use the logical vector negatives : sensor is the vector that has the values. It makes sense it comes first, since we are accessing those values.

Logical Operations 17 3 methods possible: 1. Use the logical vector negatives : 2. Use the vector whereNegatives as indices.

Logical Operations 18 3 methods possible: 3. Use the condition directly (skip the “middleman” variables) All of these are logical operations.

Quick Summary To get a logical vector: (0's and 1's) result1 = (x>=0); %var=condition; result =

Quick Summary To get a logical vector: (0's and 1's) result1 = (x>=0); %var=condition; result = To get the actual indices: result2 = find(x>=0); %var=find(condition); result =

Quick Summary To get a logical vector (mask): result1 = (x>=0); % var=condition; result = To get the indices: result2 = find(x>=0); %var=find(condition); result = To get the actual values: result = x(result1); %use the logical vector result = x(result2); %use the positions result = x(x>=0); %use the condition result = Let's see examples…

Ex1 – Filtering Data Wind tunnels are commonly used to measure pressure changes, velocities changes, etc… Some use powerful electronic sensors, some use HD cameras and dyes in the air, others (like ERAU lab) use manometers AIR FLOW Static Fluid Equation: ΔP = ρgh ±h

Ex1: Manometer 23

Ex1 – Filtering the readings % assume a vector of manometer reading % h difference in millimeters: -500<values<500 % indicate which tubes may not have not-worked, and % should be looked at (+/- 50 millimeter change) %if at least 1 was bad %display which tubes, and what were the readings % calculate difference in pressure at each point… 24

Ex1 – Filtering the readings % assume a vector of manometer reading % h difference in millimeters: -500<values<500 ManoReadings = rand(1,20)* ; % indicate which tubes may not have not-worked, and % should be looked at (+/- 50 millimeter change) shouldBeFixed = find(-50<=ManoReadings & ManoReadings<=50); if length(shouldBeFixed) ~=0 %if at least 1 was bad %display which tubes, and what were the readings end % calculate difference in pressure at each point… 25

Ex1 – Filtering the readings % assume a vector of manometer reading % h difference in millimeters: -500<values<500 ManoReadings = rand(1,20)* ; % indicate which tubes may not have not-worked, and % should be looked at (+/- 50 millimeter change) shouldBeFixed = find(-50<=ManoReadings & ManoReadings<=50); if length(shouldBeFixed) ~=0 %if at least 1 was bad disp('These tube numbers did not change much:') disp(shouldBeFixed) disp('Their values were:') disp(ManoReadings(shouldBeFixed)) end % calculate difference in pressure at each point… 26

Ex1 - Output 27 Logical operation: find() Logical operation: variableName(positions)

Ex1 – Complete the program… % assume a vector of manometer reading % h difference in millimeters: -500<values<500 ManoReadings = rand(1,20)* ; % indicate which tubes may not have not-worked, and % should be looked at (+/- 50 millimeter change) shouldBeFixed = find(-50<=ManoReadings & ManoReadings<=50); if length(shouldBeFixed) ~=0 %if at least 1 was bad disp('These tube numbers did not change much:') disp(shouldBeFixed) disp('Their values were:') disp(ManoReadings(shouldBeFixed)) end % calculate difference in pressure at each point… 28 Replace by readings from machine!

Ex2 – Sum all the positive evens % Suppose have a vector x of integers % Determine where "numbers is even" is true % Add up all the values that were even 29

Ex2 – Sum all the positive evens % Suppose have a vector x of integers % Determine where "numbers is even" is true whereTrue = (mod(x,2)==0 & x>=0); % Add up all the values that were even result = sum(x(whereTrue)); 30 Use element-wise AND

Ex2 – Sum all the positive evens % Suppose have a vector x of integers % Determine where "numbers is even" is true whereTrue = (mod(x,2)==0 & x>=0); % Add up all the values that were even result = sum(x(whereTrue)); OR % Suppose have a vector x of integers % find the POSITIONS of the positive even numbers % in x, sum the numbers at these positions 31 Use element-wise AND

Ex2 – Sum all the positive evens % Suppose have a vector x of integers % Determine where "numbers is even" is true whereTrue = (mod(x,2)==0 & x>=0); % Add up all the values that were even result = sum(x(whereTrue)); OR % Suppose have a vector x of integers % find the POSITIONS of the positive even numbers positions = find(mod(x,2)==0 & x>=0); % in x, sum the numbers at these positions result = sum(x(positions)); 32 Use only 1 symbol for AND and OR.

Ex2 – Sum all the positive evens OR directly… % Suppose have a vector x of integers % Sum the positive, even numbers of x result = sum(x(mod(x,2)==0 & x>=0)); 33 Use element-wise AND

Ex3 – How about matrices? 34 Part NumberUnit Price ($) The client orders 100 pieces of part number 65. How much is his total bill, with a tax of 6.5%?  The part number and quantity can change, hard coding is not an option!

Ex3 – Analyze table, cont. %ask user for part number, and quantity part_number = input('Enter part number: '); quantity = input('Enter quantity: '); %find the row of that part number %in table, get the actual unit price %calculate sub-total %add in taxes. 35

Ex3 – Analyze table, cont. %ask user for part number, and quantity part_number = input('Enter part number: '); quantity = input('Enter quantity: '); %find the row of that part number [row, col] = find(table == part_number); %in table, get the actual unit price %calculate sub-total %add in taxes. 36 >> [row, col] = find(table == part_number) row = 2 col = 1

Ex3 – Analyze table, cont. %ask user for part number, and quantity part_number = input('Enter part number: '); quantity = input('Enter quantity: '); %find the row of that part number [row, col] = find(table == part_number); %in table, get the actual unit price unit_price = table(row,2); %calculate sub-total %add in taxes. 37

Ex3 – Analyze table, cont. %ask user for part number, and quantity part_number = input('Enter part number: '); quantity = input('Enter quantity: '); %find the row of that part number [row, col] = find(table == part_number); %in table, get the actual unit price unit_price = table(row,2); %calculate sub-total sub_total = quantity * unit_price; %add in taxes total_bill = sub_total * (1+0.65); fprintf('Your bill adds up to: $%20.2f\n', total_bill) 38

Ex3 – Analyze table, cont. Note that this would not go well if the part_number's value is actually also one of the unit price! 39 Part NumberUnit Price ($)

Ex3 – Analyze table, cont. Note that this would not go well if the part_number's value is actually also one of the unit price! 40 >> [row, col] = find(table == part_number) row = 2 3 col = 1 2 Part NumberUnit Price ($)

Ex3 – Analyze table, cont. Note that this would not go well if the part_number's value is actually also one of the unit price! %find the row of that part number, column1 ONLY row = find(table == part_number); 41 >> [row, col] = find(table == part_number) row = 2 3 col = 1 2 Part NumberUnit Price ($) That's SLICING again! (:,1)

Ex4 – Works for strings too! 42 Simulate DNA with a string GATACCAT… The problem is: Generate the matching DNA string! A-T T-A C-G G-C Source:

Ex4 – Works for strings too! 43 Using a loop, and an if statement originalDNA ='GATACCAT'; matchDNA = []; %empty container for the matching DNA %loop for each letter for ctr = 1:length(originalDNA) if originalDNA(ctr) == 'T' %Where it is a 'T', make the 'A' matchDNA(ctr)='A'; elseif originalDNA(ctr) == 'A' matchDNA(ctr)='T'; elseif originalDNA(ctr) == 'C' matchDNA(ctr)='G'; elseif originalDNA(ctr) == 'G' matchDNA(ctr)='C'; end

Ex4 – Works for strings too! 44 Using a loop, and an if statement originalDNA ='GATACCAT'; matchDNA = []; %empty container for the matching DNA %loop for each letter for ctr = 1:length(originalDNA) if originalDNA(ctr) == 'T' %Where it is a 'T', make the 'A' matchDNA(ctr)='A'; elseif originalDNA(ctr) == 'A' matchDNA(ctr)='T'; elseif originalDNA(ctr) == 'C' matchDNA(ctr)='G'; elseif originalDNA(ctr) == 'G' matchDNA(ctr)='C'; end length() is used to count the number of elements in a vector, here: number of characters

Ex4 – Works for strings too! 45 originalDNA = GATACCAT Or.. In 5 lines! originalDNA ='GATACCAT'

Ex4 – Works for strings too! 46 originalDNA = GATACCAT matchDNA = A A Or.. In 5 lines! originalDNA ='GATACCAT' %at the T's location, put an 'A' matchDNA(originalDNA =='T')='A'

Ex4 – Works for strings too! 47 originalDNA = GATACCAT matchDNA = A A matchDNA = TAT TA Or.. In 5 lines! originalDNA ='GATACCAT' %at the T's location, put an 'A' matchDNA(originalDNA =='T')='A' %at the A's location, put a T matchDNA(originalDNA =='A')='T'

Ex4 – Works for strings too! 48 originalDNA = GATACCAT matchDNA = A A matchDNA = TAT TA matchDNA = CTAT TA matchDNA = CTATGGTA Or.. In 5 lines! originalDNA ='GATACCAT' %at the T's location, put an 'A' matchDNA(originalDNA =='T')='A' %at the A's location, put a T matchDNA(originalDNA =='A')='T' %at the G's location, put a C matchDNA(originalDNA =='G')='C' %at the C's location, put a G matchDNA(originalDNA =='C')='G'

One last keyword end It represents automatically the index of the last element in a vector 49

Wrapping Up The OR and AND operators are slightly updated What does it mean: To “evaluate” True can be evaluated as 1 False can be evaluated as 0 Logical vectors are vectors of 0's and 1's. find(condition) returns a numerical vector of positions where the condition is true. 3 methods to access (to refer to) the actual elements It works with letters too. (encryption) The keyword end (nothing to do with the if/switch/for/while) refers to the last element in the array. (note it will be black, not blue!) 50

Early File I/O To help you get started with your final project 1. Definition of “high level” 2. Is using a High Level function appropriate? 3. xlsread() 4. xlswrite() 5. dlmread() 6. dlmwrite() 51

1. Definition A file I/O function is considered HIGH-LEVEL if in ONE SINGLE COMMAND, it 1. Opens the file 2. Grabs the data 3. Stores it in variables 4. Closes the file High-level functions can be used to: 1. Load data from external sources (INPUT) 2. Save data back to a file (OUTPUT) 52

2. Wait.wait.wait… Before you decide if using a high level function is possible, evaluate the following: 1. What type of file is it? (Excel, text, jpg..) 2. Find the organization overall (data in rows, or data in columns, data placed all over the place…) 3. Recognize the delimiters (space, tabs, new lines, -, :, / any specific symbol. What makes it obvious it is a new column? What makes it obvious it is a new row?) 4. Recognize the data types (all numerical? all strings? Or combination of both) 53

2. Can High Level be used? 54

2. Can High Level be used? cont. “Neatly Organized” 1. Rows and Columns are “identifiable” 2. No “holes” anywhere 3. Always the same patterns per line 4. There is no mixes of delimiters (commas, spaces, tabs, dash.. ) 55

Questions Can these files be read using a high level function? 56

Answers Can these files be read using a high level function? 57 Yes Mixes of – and spaces. Mixes of, and spaces. Yes. White space only. Decimals are ok.

The input files (.txt,.xls,.xlsx,.m) should all be in the same directory for function calls to work! 58

2. Can High-Level be used? 59

3. xlsread() F1, help. The most general form is: Other calls possible: 60

3. xlsread() F1, help. The most general form is: Other calls possible: 61 How do we work with all this?

Example: xlsread() Reading from a grade book %load data from file [values text raw] = xlsread('grades.xlsx'); 62 Test. See results!

Example: xlsread() Reading from a grade book %load data from file [values text raw] = xlsread('grades.xlsx'); 63 Test. See results! Note that we are collecting multiple values using an array!

Results 64

3. xlsread(), cont. txt = nbs = 'Name' 'Age' 'Grade' 'Fred' '' '' 'joe' '' '' 'SaLLy' '' '' 'CharliE' '' '' 'mary' '' '' 'Ann' '' '' raw = 'Name' 'Age' 'Grade' 'Fred' [ 19] [ 78] 'joe' [ 22] [ 83] 'SaLLy' [ 98] [ 99] 'CharliE' [ 21] [ 56] 'mary' [ 23] [ 89] 'Ann' [ 19] [ 51] >> [txt nbs raw] = xlsread('grades.xlsx‘)   Variable names are up to the programmer. If named badly by mistake… BAD. The order of the return values is important.

3. xlsread(), cont. Simply omit the 2 nd and 3 rd return value to collect only numerical values. values = xlsread(‘grades.xlsx’); 66

3. xlsread(), cont. Simply omit the 2 nd and 3 rd return value to collect only numerical values. values = xlsread(‘grades.xlsx’); If a project needs all the data together, collect the 1 st and 2 nd return values into a dummy variable. [trash trash data] = xlsread(‘grades.xlsx’); 67

3. xlsread(), cont. Simply omit the 2 nd and 3 rd return value to collect only numerical values. values = xlsread(‘grades.xlsx’); If a project needs all the data together, collect the 1 st and 2 nd return values into a dummy variable. [trash trash data] = xlsread(‘grades.xlsx’); If there happen to be ‘holes’ in the spreadsheet, MATLAB fills it with a NaN value (not a number). The function isnan() can help determine where those ‘holes’ are. 68

3. xlsread(), cont. This function will not work under Citrix, since Excel is not installed on Citrix. Come to the lab to do labs and homework. 69 

4. xlswrite() Arrays can also be written to excel sheets: xlswrite(,,, ) The and arguments are optional. 70 clc clear %create phony data table = rand(5,3)*100; %print to excel xlswrite('testingTesting.xls',table)

2. Can High-Level be used? 71 NUMBERS ONLY.

5. Using Delimiters Rows are delimited by the new line character (enter key, invisible to the human eye). Columns are delimited by the same delimiter each time: Default delimiters: commas, and white space Other delimiters: any other symbol : - / F1 = help 72

5. Using Delimiters, cont. Delimiter: white space (spaces, or tabs) 73 Missing data is filled by zeros.

5. Using Delimiters, cont. Delimiter: commas Added feasibility to ‘skip’ columns 74

5. Using Delimiters, cont. Delimiter: other than the defaults 75 Specify the delimiter as the 2 nd argument.

5. Using Delimiters, cont. Delimiter: other than the defaults 76 Specify the delimiter as the 2 nd argument.

5. Using Delimiters, cont. "Neatly Organized" is important. 77 BAD RESULTS. Two delimiters (spaces and colons) in the file. Matlab is lost.

dlmwrite() M = [2, 123; 87, 4]; dlmwrite('test.txt', M, ','); File contains: 2,123 87,4 EXCEPT… 78

dlmwrite() By default, dlmwrite() saves files using Unix line endings – so if you look at the file in Notepad: This is not “wrong” – just different. This can be changed by setting the “newline” attribute when you call the function: dlmwrite('test.txt', M, ',', 'newline', 'pc'); 79