07_formattingIO - Formatting of Inputs/Outputs ENCMP 100...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Formatting of Inputs/Outputs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs Overview Inputs into a program Displaying results generated by a program revisiting disp , input , load , num2str , and save commands learning format , fprintf , sprintf , and fopen commands 2
Background image of page 2
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs The problem to be solved We will compute how long you need to own a car to make it economically advantageous to purchase a hybrid car vs. a car with a standard engine. Model MSRP Overall fuel economy 2010 Toyota Camry Sedan Hybrid $26,150 34 mpg = 6.92 L/100km 2010 Toyota Camry Sedan $20,445 26 mpg = 9.05 L/100km 2010 Ford Fusion Sedan Hybrid $27,950 39 mpg = 6.03 L/100km 2010 Ford Fusion Sedan $19,695 24 mpg = 9.80 L/100km We assume cost to own = purchase cost + gasoline cost We will prompt the user for the estimated cost of a liter of gasoline and his/her mileage per year. 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs Formatting of inputs and outputs MATLAB provides a few built-in functions for importing the inputs and formatting of the outputs Input functions include input and load Functions for formatting outputs include disp , format , fprintf , sprintf , and save Some of these functions, such as input , load , save , and disp , were introduced 4
Background image of page 4
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs The inputs The input data could be hard-coded (specified in your code) or acquired from a user or a file input command prompts the user to enter data, it accepts different data types including scalars, matrices and character strings load command allows to load data from a file load filename -ascii filename is a name of the file which you want to load - by default MATLAB assumes .mat extension of the file (and that this file is in MAT-file format), unless the filename specifies the extension. 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs The inputs ASCII and MAT-file formats MAT-file format is specific to MATLAB and it includes name and type of each variable, size of each array, and all data values this format should be used when your data is used inside the MATLAB environment. That includes MATLAB on different computers and different platforms (PC, Mac, Unix, etc.) ASCII format assumes that the values are ASCII character strings that are comma- or space-separated this format should be used when you want to exchange the data between MATLAB and 6
Background image of page 6
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs The inputs Example ASCII file (file created in slide 19 using –ascii option) 6.9200000e+000 9.0500000e+000 6.0300000e+000 9.8000000e+000 2.6150000e+004 2.0445000e+004 2.7950000e+004 2.7950000e+004 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENCMP 100 ©2011 by ECE, UofA Formatting of Inputs/Outputs The inputs Example MAT-file (file created in slide 19) MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Thu Aug 26 12:04:32 2010 ?IM???3???xœãc``ð?b6 æ€Ò À
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/27/2011 for the course ENCMP 100 taught by Professor Cockburn during the Spring '11 term at University of Alberta.

Page1 / 39

07_formattingIO - Formatting of Inputs/Outputs ENCMP 100...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online