MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.

Slides:



Advertisements
Similar presentations
DOS commands.
Advertisements

DOS & Windows O/s Prof. Sujata Rao Less 5.
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
CSE123 Introduction to Computing
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
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.
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
Or CMD/BATCH.  Title this comand makes the cmd prompt’s title whatever you would like it to be.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
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.
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.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
®® Microsoft Windows 7 for Power Users Tutorial 13 Using the Command-Line Environment.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Command Prompt Chapter 10 Introduction to Batch Files Richard Goldman February 7, 2000.
Chapter 11 File Systems and Directories. 2 File Systems File: A named collection of related data. File system: The logical view that an operating system.
A Brief introduction to MatLAB ($50 - $99 for students)
S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: User Input / Output Programming Environment.
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.
XP New Perspectives on Windows 2000 Professional Windows 2000 Tutorial 2 1 Microsoft Windows 2000 Professional Tutorial 2 – Working With Files.
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.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 : The Linux System Part 2 Lecture 2 11/14/
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
1.  Microsoft DOS (Disk Operating System) use a command line user interface.command line  A command line user interface means that the user is required.
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.
Chapter 23. Copyright 2003, Paradigm Publishing Inc. CHAPTER 23 BACKNEXTEND 23-2 LINKS TO OBJECTIVES Record, Run, Pause, and Delete Macros Record, Run,
Introduction to Programming Using C An Introduction to Operating Systems.
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.
File and Folder CLI Commands 12/24/ Agenda Overview of OS functions and the SHELL Internal v External Commands Command History Making & Modifying.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
The Command Line Yep, you need to know this. The Basics Start with the Prompt, what the computer tells you when ready for a command You type a command.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
An Introduction to Programming in Matlab Emily Blumenthal
MS-DOS is an acronym for MicroSoft Disk Operating System It is a CUI based operating system. It provides user with a command prompt (generally called.
Basic operations in Matlab
funCTIONs and Data Import/Export
Matlab.
Data Groupings: File File: a group of related records
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Using Script Files and Managing Data
Scripts In Matlab.
Your objective: to dominate! My objective: to help you dominate!
Chapter 2 MATLAB Environment
Presentation transcript:

MATLAB File Management

MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd : Print working directory – displays the full path of the present working directory. cd path : Change to directory (folder) given by path, which can be either a relative or absolute path. dir : Display the names of the directories (folders) and files in the present working directory. what : Display the names of the M-files and MAT-files in the current directory. delete file : Delete file from current directory type file : Display contents of file (text file only).

Diary Command The diary commands allows you to record all of the input and displayed output from a Matlab interactive workspace session. The commands include: diary file: Saves all text from the Matlab session, except for the prompts (>>), as text in file, written to the present working directory. If file is not specified, the information is written to the file named diary. diary off : Suspends diary operation. diary on: Turns diary operation back on. diary: Toggles diary state

Diary Example Problem: solve for s: s 2 + 5s + 6 = 0 >> diary roots >> a=1; >> b=5; >> c=6; >> x = -b/(2*a); >> y = sqrt(b^2-4*a*c)/(2*a); >> s1 = x+y s1 = -2 >> s2 = x-y s2 = -3 diary off The file roots is written in your current working directory. It can be displayed by the Matlab command type roots.

Exporting and Importing Data There are also situations in which you wish to export Matlab data to be operated upon with other programs, or to import data created by other programs. This must be done with text files written with save or read with load.

Storing and Loading Workspace Values save Stores workspace values (variable names, sizes, and values), in the binary file matlab.mat in the present working directory save data Stores all workspace values in the file data.mat save data_1 x y Stores only the variables x and y in the file data_1.mat load data_1 Loads the values of the workspace values previously stored in the file data_1.mat

Exporting Results to a Text File To write a text file data1.dat in the current working directory containing values of Matlab variables in long e format: save data1.dat –ascii Note that the individual variables will not be identified with labels or separated in any way.

Exporting Results to a Text File It is often desirable to write text files containing the values of only a single variable, such as: save data1.dat a –ascii where results are seperated by spaces.

Exporting Results to a Text File It is often desirable to write text files containing the values of only a single variable, such as: save data1.dat a –ascii -tab where results are seperated by tabs.

Importing Results from a Text File The load command followed by the filename will read the information into an array with the same name as the base name of the data file (extension removed). load elcenNS1940.dat (First copy the elcenNS1940.dat into the MATLAB\Work folder)

M-Files For simple problems, entering commands at the Matlab prompt in the Command window is simple and efficient. However, when the number of commands increases, or you want to change the value of one or more variables, reevaluate a number of commands, you will want to prepare a script, which is a sequence of commands written to a file.

M-Files By simply typing the script file name at a Matlab prompt, each command in the script file is executed as if it were entered at the prompt.

Naming M-Files The name must begin with a letter and may include digits and the underscore character. Do not give a script file the same name as a variable it computes, because Matlab will not be able to execute that script file more than once unless the variable is cleared. Do not give a script.le the same name as a Matlab command or function. You can check to see whether a function already exists by using the the which command. For example, to see whether rqroot already exists, type which rqroot.

MATLAB functions useful in M-Files Command Description disp(ans) Display results without identifying variable names echo [on|off] Control Command window echoing of script commands input(’prompt’) Prompt user with text in quotes, accept input until “Enter” is typed keyboard Give control to keyboard temporarily. Type Return to return control to the executing script M-file. pause Pause until user presses any keyboard key pause(n) Pause for n seconds WaitforbuttonpressPause until user presses mouse button or keyboard key

Script Example Derive and apply the quadratic equation by first expressing the quadratic polynomial in parametric form, as 2 + bs + c = 0

Script Example % rqroots: Quadratic root finding script format compact; % prompt for coefficient input a = input(’Enter quadratic coefficient a: ’); b = input(’Enter quadratic coefficient b: ’); c = input(’Enter quadratic coefficient c: ’); disp(’’) % compute intermediate values x & y x = -b/(2*a); y = sqrt(b^2-4*a*c)/(2*a); % compute and display roots s1 = x+y; disp(’Value of first quadratic root: ’),disp(s1); s2 = x-y; disp(’Value of second quadratic root: ’),disp(s2);