Matlab script and function m-files


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

MATLAB Script Files

  • Lect 19 P.
  • Winter Quarter
  • When the file is not in the current working directory, a cd or chdir command may be issued to change the directory.
  • >> cd a:\ % Make a:\ the current working directory
  • >> d13

MATLAB Demo

  • Lect 19 P.
  • Winter Quarter
  • %MATLAB Example use of ginput
  • clear, clf, hold off
  • axis ([0, 10, 0, 10])
  • hold on
  • plot ([1, 2, 2, 1, 1],[2, 2, 3, 3, 2])
  • text (1, 1.6, 'Click inside box to quit')
  • while 1
  • [x, y, buttun] = ginput (1)
  • if buttun == 1, plot (x, y, '+r'), end
  • if buttun == 2, plot (x, y, 'oy'), end
  • if buttun == 3, plot (x, y, '*g'), end
  • if x > 1 & x < 2 & y > 2 & y < 3, break; end
  • end
  • hold off

MATLAB Function Files

  • Lect 19 P.
  • Winter Quarter
  • A MATLAB function file (called an M-file) is a text (plain ASCII) file that contains a MATLAB function and, optionally, comments.
  • The file is saved with the function name and the usual MATLAB script file extension, ".m".
  • A MATLAB function may be called from the command line or from any other M-file.

MATLAB Function Files

  • Lect 19 P.
  • Winter Quarter
  • When the function is called in MATLAB, the file is accessed, the function is executed, and control is returned to the MATLAB workspace.
  • Since the function is not part of the MATLAB workspace, its variables and their values are not known after control is returned.
  • Any values to be returned must be specified in the function syntax.

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