1. Definition 2. Creating Cell Arrays 3. Augmenting Cell Arrays 4. Referencing Cell Arrays 5. Special case 6. Spreadsheets 1.

Slides:



Advertisements
Similar presentations
Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
Advertisements

Microsoft Office XP Microsoft Excel
1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
1 Linking & Consolidating Worksheets Applications of Spreadsheets.
Tutorial 8: Developing an Excel Application
Chapter 07: Lecture Notes (CSIT 104) 1111 Exploring Microsoft Office Excel 2007 Chapter 7 Data Consolidation, Links, and Formula Auditing.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
CS 275Tidwell Course NotesPage 110 Chapter 7: Getting Input From Users Designing interactive forms, in which the user is expected to supply information.
Chapter 10 Introduction to Arrays
Viewing and using data from a SonoBatch run. SonoBatch processing generates tab-delimited text files readable as spreadsheets. To open in Excel, select.
Automating Tasks With Macros
String Variables Visual Basic for Applications 4.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
MATLAB Cell Arrays Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
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.
1 Introduction to Spreadsheets Bent Thomsen. 2 What is an electronic spreadsheet? It is the electronic equivalent of an accounting worksheet, comprised.
ADVANCED MICROSOFT POWERPOINT Lesson 6 – Creating Tables and Charts
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
Technology Basics Creating Worksheet Formulas. 2 Understand Formulas Equations used to calculate values in cells are called formulas. Formulas consist.
Excel 2007 Part (2) Dr. Susan Al Naqshbandi
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
Lesson 1 – Microsoft Excel The goal of this lesson is for students to successfully explore and describe the Excel window and to create a new worksheet.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Working with a Database
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
GUI Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Cell Arrays 1.Definition 2.Creating Cell Arrays 3.Referencing Cell Arrays 4.Augmenting Cell Arrays 5.Use of Cell Arrays 1.
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.
Cell Arrays 1. Data Types (Review) 2. General Concept 3. Creating Cell Arrays 4. Augmenting Cell Arrays 5. Referencing Cell Arrays 1. The entire cell/
1. Reminder of Symbols 2. Dialog Boxes 3. listdlg() 4. msgbox() 5. questdlg() 6. menu() Dialog Boxes Applications of Cell-Arrays 1.
Introduction to File I/O High-Level Functions 1.Data files 2."High level" File I/O 3.dlmread() 4.xlsread() 1.
1.Reminder of Symbols 2.Dialog Boxes 3.Output-centric dialogs 4.Input-centric dialogs Dialog Boxes Applications of Cell Arrays 1.
Software Project Planning Defining the Project Writing the Software Specification Planning the Development Stages Testing the Software.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
With Microsoft Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2007 Comprehensive.
CMPS 1371 Introduction to Computing for Engineers FILE Input / Output.
File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Working with Arrays in MATLAB
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.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
JavaScript, Fourth Edition
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Excel 2007 Part (3) Dr. Susan Al Naqshbandi
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Cell Arrays Lecture 2/8/ Data Types (Review) 2. General Concept 3. Using Cell-Arrays 1. Syntax/Symbols 2. Dialog Boxes 1.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
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()
Project Planning Defining the project Software specification Development stages Software testing.
Chapter 7 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
Excel Tutorial 8 Developing an Excel Application
Chapter 7: Getting Input From Users
© 2016 Pearson Education, Ltd. All rights reserved.
Dialog Boxes Applications of Cell-Arrays
INTRODUCTION TO SPREADSHEET APPLICATIONS
Developing an Excel Application
Cell Arrays Definition Creating Cell Arrays Referencing Cell Arrays
Arrays.
Presentation transcript:

1. Definition 2. Creating Cell Arrays 3. Augmenting Cell Arrays 4. Referencing Cell Arrays 5. Special case 6. Spreadsheets 1

 Recall the workspace frame in MATLAB. Currently, 4 types of data have been seen. They are called:  This chapter teaches how to operate more specifically with the cell array 2

 Data type that holds information indexed in containers called cells  A cell can hold any data type- string, integer, float, another cell array… 3 Simply It is an ARRAY of CELLS

 Create a cell array by using the {} brackets  Separate each element in the array with a comma 4 Curly braces – not parentheses, not brackets!

 Plot them using cellplot()! 5 FYI: It is just a representation. J is in the first box, o in the second, e in the third.

 Adding on a new cell to the array  Example, add on the string 'def'. 6

 { } are not used to augment. They are strictly used to create new cell-arrays from scratch.  The curly braces indicate ‘def’ is added OUTSIDE of the cell-array C – i.e. C is a completely new cell-array! 7 NOT what we wanted...

 Augment the same as with normal arrays: use brackets 8

 Can a 2D cell-array exist? Of course.  Still use the ; operator to add a new row. 9

 There are 2 ways to reference a cell array, depending on the task: 1. Get the entire container as a whole. (Do not open the doors to see the content)  to move the container  to extract/copy/replace the container  to delete the container 2. Get the content inside the container. (Open the doors, and use the content)  To change its content  To display/print its content 10

1. Get the entire container as a whole. (Do not open the doors to see the content) 2. Get the content inside the container. (Open the doors, and use the content) 11 Parentheses () Curly Braces {}

 Assume C starts with: %option1: refer to & delete the 2 nd container 12

 Assume C starts with: %option1: refer to & delete the 2 nd container %option2: refer to & delete the content of the 2 nd container 13

 This is particularly important if you wish to use the values mathematically (equations, … )  For example:  Using the variable X mathematically creates issues The content (numerical value 2) is still inside the container, as indicated per the brackets.

 To use this variable X mathematically creates an error  After all, this is what MATLAB tries to execute: result = 2* ?

 Recall to use curly braces to access the CONTENT. 16 Use curly braces {}. Notice the lack of [] around the result.

 To conclude, also use curly braces to replace elements. 17 Initial data-base (name, age, weight) Fix the name

 What if there is an array within a cell? 18 1) max? 2) last score?

 What if there is an array within a cell?  "Max of the content of container 2". Use { }. 19 1) max?

 The following requires patient imagination skills, but it works and makes sense! 20 Simply: "Reference to the 3 rd element in the CONTENT of the 2 nd container" Simply: "Reference to the last element in the CONTENT of the 2 nd container"

 Most would prefer storing the content in a intermediate variable, then referencing that variable. 21

 Syntax: [NUM,TXT,RAW]=xlsread(FILE)  You can select which sheet you want to read into Matlab(the first sheet is the default)  Reads data from the first worksheet in the Microsoft Excel spreadsheet file named FILE  NUM is a matrix with just the numerical values found in the table.  TXT is a cell array with the textual information found in the table.  RAW is a cell array with numbers and text  Syntax: xlswrite(FILE,ARRAY) 22 Example!

 Syntax: RESULT = dlmread(FILENAME)  The delimiter is inferred from the formatting of the file.  All data in the input file must be numeric.  Fills empty delimited fields with zero  dlmread( ) cannot handle text data file properly 23

 Numbers have different precisions and formats delimiters (spaces, tabs, ;) separate columns Space delimiterComma delimiter , 3.00, 32 2, 3.20, 36 3, 2.40, 35 4, 1.60, 37 5, 2.80, 39

 Syntax: RESULT= importdata(FILENAME)  importdata( ) will separate the text columns and the numeric columns into separate fields in a structure  The contents of the structure can be copied into numeric variables for analysis 25

 Cells arrays are ‘cargo-ships’  Rectangular arrays allowing storage of different data-types into 1 variable.  Cell-arrays use all types of braces: Creating/hard-coding: Braces { } Referencing to content:Braces { } Augmenting:Brackets [ ] Referencing to container: Parentheses ()  For more useful information about Cell Arrays, please visit: g/br04bw6-98.html g/br04bw6-98.html 26 Most likely to be used often!

1. Dialog Boxes: Overview 2. Inputdlg() 3. listdlg() 4. msgbox() 5. questdlg() 6. menu() 27

 Dialog boxes are “popup windows” that allows another means to communicate with the user.  There are dialog boxes to collect input: inputdlg(), listdlg(), menu(), questdlg()  And there are dialog boxes to produce output: msgbox(), warndlg() 28 99% of the time, the command deals with cell arrays, either as arguments, as return-values, or both!

 Timing wise:  Modal (“waiting”) – they prevent the program from continuing until the box is closed  Non-modal (“non-waiting”) – the program continues execution while the box remains open  Examples:  Input boxes are generally modal – the program waits for input before continuing. This is not changeable.  Output boxes default to non-modal (“non-waiting”) but can be made modal. 29

 inputdlg() – much like the input() function, except…  It is presented in a GUI form  There can be multiple prompts and multiple values provided by the user.  ALL user-provided information is returned as strings in a cell array! That’s why learning about cell-arrays is important! 30

 Prompt the user for the coefficients to the quadratic equation, then solve for the roots.  Requirements: Use a Graphical User Interface (GUI) to prompt the values, specifically inputdlg() 31 …

 Arguments  A cell array of strings: This is the set of prompts for the user. For example: prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'}  Return Values  one (1) cell-array of strings: What the user provided in the boxes  Full Example prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'}; coeffs = inputdlg(prompts); 32 Cell-array, indicated by the curly braces.

33  When collecting numbers, use str2double() to convert the cell-array (cargo-ship) into a numerical vector: coeffs = str2double(coeffs);

34 clear clc prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'}; flag=1; % No invalid inputs, or imaginary roots while (flag) % Collect the coeff’s from the user coeffs = inputdlg(prompts); coeffs = str2double(coeffs); a = coeffs(1); b = coeffs(2); c = coeffs(3); if (a==0 || (b^2 - 4*a*c) < 0) % No invalid inputs, or imaginary roots fprintf('invalid values\n'); else flag=0; end %calculate roots roots(1) = (-b + sqrt(b*b-4*a*c))/(2*a); roots(2) = (-b - sqrt(b*b-4*a*c))/(2*a)

35 clear clc prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'}; flag=1; % No invalid inputs, or imaginary roots while (flag) % Collect the coeff’s from the user coeffs = inputdlg(prompts); coeffs = str2double(coeffs); a = coeffs(1); b = coeffs(2); c = coeffs(3); if (a==0 || (b*b - 4*a*c) < 0) % No invalid inputs, or imaginary roots fprintf('invalid values\n'); else flag=0; end %calculate roots roots(1) = (-b + sqrt(b*b-4*a*c))/(2*a); roots(2) = (-b - sqrt(b*b-4*a*c))/(2*a) Extract the values from the vector: Must this be done, or should it be done for convenience?

36 clear clc prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'}; flag=1; % No invalid inputs, or imaginary roots while (flag) % Collect the coeff’s from the user coeffs = inputdlg(prompts); coeffs = str2double(coeffs); if (coeffs(1)==0 || (coeffs(2)^2 - 4*coeffs(1)*coeffs(3)) < 0) % No invalid inputs, or imaginary roots fprintf('invalid values\n'); else flag=0; end %calculate roots roots(1) =(-coeffs(2) + sqrt(coeffs(2)^2- 4*coeffs(1)*coeffs(3)))/(2*coeffs(1)); roots(2) =(-coeffs(2) - sqrt(coeffs(2)^2- 4*coeffs(1)*coeffs(3)))/(2*coeffs(1)) Really.. 

37 clear clc prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'}; flag=1; % No invalid inputs, or imaginary roots while (flag) % Collect the coeff’s from the user coeffs = inputdlg(prompts); coeffs = str2double(coeffs); a = coeffs(1); b = coeffs(2); c = coeffs(3); if (a==0 || (b*b - 4*a*c) < 0) % No invalid inputs, or imaginary roots fprintf('invalid values\n'); else flag=0; end %calculate roots roots(1) = (-b + sqrt(b*b-4*a*c))/(2*a); roots(2) = (-b - sqrt(b*b-4*a*c))/(2*a) Since the prompts do not change each time it loops, avoid having this line within the loop. Time & effort consuming for Matlab.

38  Syntax: [SELECTION,OK]=listdlg('ListString',S)  Creates a modal list-selection dialog box  SELECTION is a vector of indices of the selected strings ▪ length 1 in the single selection mode ▪ This will be [] when OK is 0  OK=1 if you push the OK button,  OK=0 if you push the Cancel button or close the figure.

Inputs are in parameter/value pairs (i.e. they go 2 by 2): Parameter goes 1st, value of the parameter goes 2nd. The actual string: 39

myList is a CELL ARRAY of string: { } Why cell arrays? The length of each selection varies widely, and an regular-array would not be rectangular. 40

41 The Select All button is gone.

 Syntax: msgbox(Message, Title, Icon)  Message is a string vector, string matrix or cell array.  Could be modal or non-modal  Title: specifies the title of the message box  Icon: specifies which Icon to display in the message box. ▪ Icon is 'none', 'error', 'help', 'warn', or 'custom'. The default is 'none'. 42

 Syntax: ButtonName = questdlg(Question, Title,Btn1,Btn2,Btn3,DEFAULT)  creates a modal dialog box that automatically wraps the cell array or string  Up to 3 custom button names may be specified  default = String that is the default button  button = string on the button that was clicked  If the dialog is closed without a valid selection, the return value is empty. 43

 button = string on the button that was clicked 44

 Syntax: button = menu('qstring','bt1','bt2',……,'btn')  qstring = question to ask user  bt1 = String to show on Button #1  bt2 = String to show on Button #2  Can have as many options as desired.  There is no default answer.  Return value: Button number clicked (not the string) 45

46

47

 Dialog boxes are user friendly but time taking  We saw:  inputdlg()  listdlg()  msgbox()  questdlg()  menu()  NEVER learn the syntax by heart. Practice it enough, then use the doc to remind yourself quickly! 48

 If you want to do more than fundamental dialog boxes, study the MATLAB help documentation.  html#f F1 = Help