Matlab

This program handles vectors and matrices nicely. It does do regression and has nice plots.

For a postscript version of the MATLAB Primer make sure that you have set Netscape (or other viewer) to recognize and start up ghostview (full name: /psoft/X11R6/bin/ghostview) when it encounters a file ending in .ps, then click here: MATLAB Primer .

Startup

This program will also run in an Emacs window, but for now, start it in an xterm window by typing > matlab. Matlab is based in the C language and like C needs semicolons at the end of each line. To assign a value to a variable use the equal sign, functions are created with emacs and saved in the current directory as *.m files. Type help function for an example.

Help is envoked simply by typing >> help function-name. Just help gives a list of general topics, for instance iofun is a group of low-level file input-output functions. To see the list of those functions, type help iofun, then pick one of those for another help command.

Example To simplify data entry into Matlab, edit the tires.data file (created using emacs) to change all occurences of three spaces to a comma and two spaces. Then we'll read it into matlab.

>> tires = dlmread('tires.data', ',')
>> hardness = tires(1:30,1)
>> size(tires)
>> tensile_strength = tires(1:30,2)
>> abrasion_loss = tires(1:30,3)
>> plot(hardness,abrasion_loss,'*')
>> plot3(hardness,tensile_strength,abrasion_loss,'o')
   
To perform the regression, we need to build the X matrix. Matlab expects you to include a vector of ones if you want an intercept term. The apostrophes below give transposes. Semicolons are used to break up rows of a matrix.
>>  tirex = [ones(1,30); hardness'; tensile_strength']';
>> size(tirex)
>> [B,BINT,R,RINT,STATS] = regress( abrasion_loss,tirex, .05)
>> plot(tirex*B,R,'o')

Exiting

Just type exit.
For more information see Dockery's notes or the Matlab primer (190Kb postscript) or vist the Matlab homepage.


Information about unix and emacs.

Other Stat package demos:


Back to MSU Math Department Home Page


Author: Jim Robison-Cox
Last Updated: Tuesday, 14-Jun-2011 16:52:23 MDT