% 10/4/05 Introduction to Matlab % You can download Matlab at % http://web.mit.edu/afs/athena/software/matlab/www/home.html % The Mathworks site has some useful introductory pages: % http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/learn_matlab.html % create a vector x = 1:10 % extract the 7th element x(7) % create a matrix x = [0, 1, 2; 10, 11, 12; 20, 21, 22]; % extract the element in position (2,3) x(1,2) % Scripts %-------- % You can put a collection of commands into a file with the .m extension. % Typing the filename is equivalent to typing all of the commands at the % command line. This file is a script. % Functions %----------- % You can also create functions. Put the next two lines in a % file called mysquare.m : % function y = mysquare(x) % y = x^2; % Now we can call the function mysquare(3); % Try help function % to learn more about functions % Getting help % -------------- % figure out the name of the standard deviation function lookfor deviation % read the help file about the standard deviation function help std % Debugging %---------- % Placing "keyboard" somewhere in a script or a function stops execution at % that point. Use dbstep to advance and dbcont to continue execution. dbstop if error % is very useful -- it will stop your program when an error % happens and let you track down the problem by examining the % variables in memory % Other useful commands %----------------------- % Try exploring: % size, find, whos, sum, mean, max, min, repmat % Making graphs %-------------- % Try exploring: plot, bar, print