1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.

Slides:



Advertisements
Similar presentations
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Advertisements

Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Programming with MATLAB
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
Lecture 7 Sept 17 Goals: Complete Chapter 4 Chapters 5 and 6.
ES 100: Lecture 7 String Functions 1.Log in 2.Open MATLAB 3.Change the current directory and path to U: 4.Change the numeric display to compact (File,
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Lecture 5 Input and Output inputfprintf © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Input/Output Functions Selim Aksoy Bilkent University Department of Computer Engineering
Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low.
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.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
AN ENGINEER’S GUIDE TO MATLAB
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.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 4.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 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.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
Compiled Matlab on Condor: a recipe 30 th October 2007 Clare Giacomantonio.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Data Structure & File Systems Hun Myoung Park, Ph.D., Public Management and Policy Analysis Program Graduate School of International Relations International.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
CMPS 1371 Introduction to Computing for Engineers FILE Input / Output.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Script M-Files Group of Matlab commands placed in a text file with a text editor. Matlab can open and execute the commands exactly as if they were entered.
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
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 &
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
GENERATION OF RANDOM NUMBERS
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
CSE123 Lecture 3 Files and File ManagementScripts.
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.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
File Operations in Matlab Load / Save *.dat, *.mat vs. -ascii fopen /fclose.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATLAB – More Script Files
Introduction to Programming for Mechanical Engineers (ME 319)
Using Script Files and Managing Data
Advanced Data Import & Export Jeff Henrikson
Review Make sure current directory is set properly Create a diary
funCTIONs and Data Import/Export
Islamic University of Gaza
Recapitulation of Lecture 5
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.

In the previous lectures 2  Matlab Windows (workspace, m-file,…)  Working with Arrays  Mathematical Operations with Arrays  Generating Random numbers

Agenda 3  Using Script Files and Managing Data  Input Command  Output Commands: disp, fprintf  Save / load Commands  Importing / Exporting Data.

4  To enable the user to assign a value to the variable in the run-time. This is done by using the input command for creating the variable. Input Command

5  Example: Chapter4 Example4.m Input Command

6  Two commands that are frequently used to generate output are disp and fprintf.  The disp command displays the output on the screen.  The fprintf command can be used to display the output on the screen or to save the output to a file. Output Commands

7  The disp command: disp  Example: PopTable.m Displaying data in a table

8  Example: PopTable.m disp

9  The fprintf command:  Using the fprintf command to display text:  Using the fprintf command to display text and numerical values: fprintf

10 fprintf  – (minus sign): Left-justifies the number within the field.  precision specifies the number of digits to the right of the decimal point.

11  The last element in the formatting elements, which is required, is the conversion character, which specifies the notation in which the number is displayed. Some of the common notations are: fprintf

12  Example: Chapter4Example7.m fprintf \n: moves to a new line

13  Using the fprintf command to save output to a file: When dealing with files, be careful with the path of the file. (it is better to have the file in the current directory) fprintf: saving output to a file

14  Step a: fprintf: saving output to a file file identifier.

15  Step b:  Step c: fprintf: saving output to a file

16  Example 5: fprintf: saving output to a file

17  Example 5: fprintf: saving output to a file

18 fprintf: saving output to a file  Example 5:

19  The save command: you can save all variables in the work space: Save to file All of the variables currently in the workspace are saved in a file named file_name.mat that is created in the current directory. In mat files, which are written in a binary format, each variable preserves its name, type, size, and value. These files cannot be read by other applications.

20  The save command: you can save some variables in the work space:  Saving variables in ascii format: Save to file

21  The load command: is used to retrieve data from (.mat) files (created by save command), ascii files or text (.txt) files.  loading data from (.mat) files: Load from file

22  loading data from text files (.txt): Load from file

23  Import from Excel sheet: Importing and exporting data  Export to Excel sheet:

24 Importing and exporting data  Example: importing data from Excel sheet:

25 Exercise

26 Exercise: solution: m-file

27 Exercise: solution: result in Command Window

28 Exercise Modification Solve the previous exercise but instead of using the input command assume that the values are stored in Vinput.txt file, also save the results in Vresults.txt file.

29 solution: input text file and m-file

30 solution: output text file

Material & problems 31  We have covered Chapter 4 from Gilat.  Problems you can try: Sample Problem 4-1 1,2,5,10,19,22

Assignment #1, Due Date is 19/11/  Problem: 23 in section 4.7, page 130 in Gilat You have to deliver a screen shoot of your Matlab code and result.