Presentation is loading. Please wait.

Presentation is loading. Please wait.

Engr 0012 (04-1) LecNotes 09-01 loading data from files >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==> c:\temp\speed_mpg.dat.

Similar presentations


Presentation on theme: "Engr 0012 (04-1) LecNotes 09-01 loading data from files >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==> c:\temp\speed_mpg.dat."— Presentation transcript:

1 Engr 0012 (04-1) LecNotes 09-01 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

2 Engr 0012 (04-1) LecNotes 09-02 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 response is assigned as a string to variable file_name

3 Engr 0012 (04-1) LecNotes 09-03 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 contents of file assigned to designated variable name

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

5 Engr 0012 (04-1) LecNotes 09-05 comparing two forms of load command load filename.dat xydata = load(file_name) filename.dat is the name of a file in the current workspace file_name is a string (variable) that points to the file file contents assigned to a new variable called filename file contents assigned to designated variable ( xydata ) “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

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

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

8 Engr 0012 (04-1) LecNotes 09-08 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)

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

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

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

12 Engr 0012 (04-1) LecNotes 09-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


Download ppt "Engr 0012 (04-1) LecNotes 09-01 loading data from files >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==> c:\temp\speed_mpg.dat."

Similar presentations


Ads by Google