1 / 12

Engr 0012 (04-1) LecNotes 09-01

loading data from files. >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==> c:tempspeed_mpg.dat file_name = c:tempspeed_mpg.dat. >> xydata = load(file_name) xydata = (contents of data file displayed). >> speed = xydata(:,1)' speed =

cato
Download Presentation

Engr 0012 (04-1) LecNotes 09-01

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. loading data from files >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==>c:\temp\speed_mpg.dat file_name = c:\temp\speed_mpg.dat >> xydata = load(file_name) xydata = (contents of data file displayed) >> speed = xydata(:,1)' speed = 30 35 40 45 50 60 65 >> mpg = xydata(:,2)' mpg = 37.1000 36.7000 35.4000 33.4000 30.4000 22.1000 16.7000 Engr 0012 (04-1) LecNotes 09-01

  2. response is assigned as a string to variable file_name loading data from files >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==>c:\temp\speed_mpg.dat file_name = c:\temp\speed_mpg.dat asking user to identify the filename/path where data is kept 's' tells MATLAB the input data will be a string respond with file name and location path can be omitted if file is in current MATLAB directory Engr 0012 (04-1) LecNotes 09-02

  3. contents of file assigned to designated variable name loading data from files >> xydata = load(file_name) xydata = (contents of data file displayed) functional form of load command file_name must be a string identifying where file can be found Engr 0012 (04-1) LecNotes 09-03

  4. loading data from files >> speed = xydata(:,1)' speed = 30 35 40 45 50 60 65 extracting x-y vectors and transposing in same step Engr 0012 (04-1) LecNotes 09-04

  5. comparing two forms of load command file_name is a string (variable) that points to the file filename.dat is the name of a file in the current workspace file contents assigned to designated variable (xydata) file contents assigned to a new variable called filename “hardwired” - cannot change data file name generic - filename can be changed by asking user good when working directly in MATLAB workspace preferable for use in function to get data from any file Engr 0012 (04-1) LecNotes 09-05

  6. x-variable y-variable symbol type displaying data in a graph >> plot(speed,mpg,'r*') Engr 0012 (04-1) LecNotes 09-06

  7. displaying data in a graph 'r*' Engr 0012 (04-1) LecNotes 09-07

  8. annotating your graph >> xname = input( 'Enter x-axis name ==> ','s'); Enter x-axis name ==>speed >> yname = input( 'Enter y-axis name ==> ','s'); Enter y-axis name ==>mpg >> graphname = input( 'Enter graph name ==> ','s'); Enter graph name ==>MPG versus Speed >> xlabel(xname) >> ylabel(yname) >> title(graphname) Engr 0012 (04-1) LecNotes 09-08

  9. annotating your graph not linear, i.e., not y = mx+b title y-axis label x-axis label Engr 0012 (04-1) LecNotes 09-09

  10. searching for a straight line >> semilogy(speed,mpg,'*r') note change in y-scale Engr 0012 (04-1) LecNotes 09-10

  11. searching for a straight line >> loglog(speed,mpg,'*r') note change in both axis scales Engr 0012 (04-1) LecNotes 09-11

  12. recap on data analysis to date 1. function to load data, extract x & y components, get indep var name, dep var name, data set title, and symbol type needs: results: xpts, ypts, xname, yname, graphname, symbol 2. script that calls get data function, asks user for choice of plot type (linear, semilog, log-log), and displays requested (annotated) plot Engr 0012 (04-1) LecNotes 09-12

More Related