Matlab script and function m-files


Download 305 Kb.
bet1/4
Sana29.03.2023
Hajmi305 Kb.
#1306768
  1   2   3   4
Bog'liq
functions in MATLAB

MATLAB: Script and Function Files

  • Lect 19 P.
  • Winter Quarter
  • Lecture 19

MATLAB Script Files

  • Lect 19 P.
  • Winter Quarter
  • A MATLAB script file (Called an M-file) is a text (plain ASCII) file that contains one or more MATLAB commands and, optionally, comments.
  • The file is saved with the extension ".m".
  • When the filename (without the extension) is issued as a command in MATLAB, the file is opened, read, and the commands are executed as if input from the keyboard. The result is similar to running a program in C. The following slide is the contents of an M-file. Note that there are no prompts (>>).

MATLAB Script Files

  • Lect 19 P.
  • Winter Quarter
  • % This is a MATLAB script file.
  • % It has been saved as "d13.m".
  • load d13.dat; %Load data file
  • voltage = d13( : , 4); %Extract volts vector
  • time = .005*[1:length(voltage)]; %Create time vector
  • plot (time, voltage) %Plot volts vs time
  • xlabel ('Time in Seconds') % Label x axis
  • ylabel ('Voltage') % Label y axis
  • title ('Bike Strain Gage Voltage vs Time')
  • grid %Put a grid on graph

MATLAB Script Files

  • Lect 19 P.
  • Winter Quarter
  • The preceding file is executed by issuing a MATLAB command:
  • >> d13
  • This single command causes MATLAB to look in the current directory, and if a file d13.m is found, open it and execute all of the commands. The result, in this case, is a plot of the data from d13.dat.
  • If MATLAB cannot find the file in the current working directory, an error message will appear.

Download 305 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling