This document discusses various topics related to script files and data management in MATLAB including:
1) Using script files to define and assign variables, and different ways to provide input to script files.
2) Output commands in MATLAB like disp and fprintf to display text and variables, along with formatting options.
3) The save and load commands to save and load variables and workspace data to and from file.
4) Importing and exporting data to and from Excel files using commands like xlsread and xlswrite.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views11 pages
Matlab Lecture 5
This document discusses various topics related to script files and data management in MATLAB including:
1) Using script files to define and assign variables, and different ways to provide input to script files.
2) Output commands in MATLAB like disp and fprintf to display text and variables, along with formatting options.
3) The save and load commands to save and load variables and workspace data to and from file.
4) Importing and exporting data to and from Excel files using commands like xlsread and xlswrite.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11
Lecture 5
Chapter 4 Using Script Files and Managing Data
• Using Script Files and Managing Data • The MATLAB workspace and workspace window
The MATLAB workspace and the workspace window
Chapter 4 Input to a Script File • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File There are three ways • The variable is defined and assign the value in script file • The variable is defined and assign the value in Command window • The variable is defined in the script file, but a specific value is entered in the Command window when the script file is executed variable_name = input(‘string with a message’) variable_name = input(‘prompt message’,‘s’) Chapter 4 Output Commands • Using Script Files and There are two ways Managing Data • The disp Command (only text) • The MATLAB workspace • disp(name of a variable) or disp(‘text as string’) and workspace window • The fprintf Command (text+data) • Input to a Script File • fprintf(‘text typed in as a string’) • Escape Characters • Output Commands • \n use for new line • \b use for backspace • \t use for horizontal tab • fprintf(‘text as string %-5.2f additional text’, variable_name) • Flags • Flag (-) Left-justify the number within field • Flag (+) Print a sign character • Flag (0) ass zeros if necessary • Field width 5.2 means minimum 5 digits, 2 decimals • Conversion character • e, E use for exponential notation • f use for fix-point notation • g, G use for shouter of e, E or f notation • i use for integer Chapter 4 Output Commands • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File • Output Commands Chapter 4 Output Commands • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File • Output Commands Chapter 4 Output Commands • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File • Output Commands Chapter 4 Output Commands • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File • Output Commands Chapter 4 The Save and Load Commands • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File • Output Commands • Save Commands save file_name or save(‘file_name’) • Save, Load Commands save file_name var1… or save(‘file_name’,’var1’,…) save –ascii file_name save only values of variable • Load Commands load file_nameor load(‘file_name’) load file_name var1… or load(‘file_name’,’var1’,…) for ascii file_name saved only load file_nameor variable_name=load(‘file_name’) for .text file_name saved only load file_name.text or variable_name=load(‘file_name.text’) Chapter 4 Importing and Exporting Data • Using Script Files and Managing Data • The MATLAB workspace By Command by Import Wizard and workspace window Format is known format is not known • Input to a Script File Excel, csv, ascii, lotus 123, etc. (Excel is most useful) • Output Commands Import and Export in Excel • Save, Load Commands Import By Command • Import and Export Data variable_name=xlsread(‘filename’) variable_name=xlsread(‘filename’,‘sheet_name’) variable_name=xlsread(‘filename’,‘sheet_name’,‘range’) Export by Command xlswrite(‘filename’,variable_name) xlswrite(‘filename’,’sheet_name’,variable_name) xlswrite(‘filename’,’sheet_name’,’range’,variable_name) Using import Wizard By using command to active import wizard uiimport By choosing the data from the directory File\Import Data Chapter 4 Practice and Exercise • Using Script Files and Managing Data • The MATLAB workspace and workspace window • Input to a Script File • Output Commands • Save, Load Commands • Import and Export Data • Practice and Exercise Practice and exercise