Scientific Computing & Visualization
Help Contact
About Accounts Computation Visualization Documentation Services

Introduction to MATLAB

File Types

  • script m-files ( variables global).
    Create a file by the name, say, mytest.m.
    Contents of mytest.m :
    x=45*pi/180; % convert degrees to radians
    a=sin(x); % compute sine 45 degrees
    b=cos(x); % compute cosine 45 degrees
    disp('sin(45*pi/180)') % print header
    disp(a) % print result
  • function m-files ( variables are local unless appear on function declaration line).
    function mean=avg(x)
    % Usage: >> mean=avg(x);
    % x - input matrix of which an average is sought
    % mean - output; the average of x (sum(x)/n)
    n = size(x); % find out the size of the matrix
    N = prod(n); % number of elements in x
    mean = sum(x)/N; % the average
  • mat-file
  • mex-file

left right up
Documentation
Boston University
Boston University
 
OIT | CCS | July 7, 2009  
Scientific Computing & Visualization Boston University home page Boston University home page