{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

View Full Document Right 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
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. We will show and plot the cost to own as a 3
Image of page 3

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

View Full Document Right 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 before. Today we will discuss them and the 4
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. - if the extension is not .mat then MATLAB assumes that the data is in 5
Image of page 5

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

View Full Document Right 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 other applications 6
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
Image of page 7

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

View Full Document Right 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 æ€Ò À å3"aN NK° ONÌ-ªÌ€ªã„ª[çþ°Jd± ´?± = °???-???xœãc``p?b6 æ€Ò À å3"a?-5>91·¨’ÊŸ5$?sÝ K???/???xœãc``p?b6 æ€Ò À
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern