This workshop is an introduction to the MATLAB statistical package and scripting language with a focus on applications for the social sciences. The introductory workshop covers the basics of Matlab: setting up and starting Matlab, using the Command and Editor windows, defining variables and entering data, conduct standard statistical analyses, and basic plotting functions.
What is Matlab?
A statistical package (like SPSS, R) and scripting language (like C, C++, Python) combined with a huge graphics and visualizations tools. It is used by researchers across many fields to construct stimuli, run experiments, and analyze data.
Goals of this workshop:
- Learn about the range of tools available in Matlab
- Learn how to start Matlab and use the command window
- Learn how to define and manipulate variables
- Learn how to write simple scripts
Obtaining Matlab
Matlab is a proprietary software which runs on licenses (personal, group, network, or site licenses for whole campuses). Unfortunately UCSC does not (yet) have a site license for Matlab, but you can purchase your own student licenses here: www.mathworks.com
Using the Command Window like a graphing calculator
- List of basic Matlab commands and built-in functions
- Defining variables
v(2,1)
v = [2 5 3; 1 6 4];
w = v.^2 + 3;
- Plotting: scatter plots and bar graphs
x = [0 : .1 : 10];
y = sin(x);
figure(1); plot(x,y)
bar(xy)
- Simple stats: mean, median, std
[mean(x) median(x) mode(x) std(x)]
The Editor Window: writing and running scripts
- Script = list of commands
- Suppressing output using “;”
y = pi;
- Querying variables
y
- “if” statements
if y>3
display('yes')
end
- “for” loops
for i=1:10
display(num2str(i));
end
- Commenting
%anything following a percent sign will be ignored
- Running and debugging scripts
using the 'keyboard' command within scripts to pause and query variables
Getting help within Matlab (press F1 or click on Product Help) and outside of Matlab:
www.mathworks.com/help/matlab/getting-started-with-matlab.html
Download the slides from the October 19 2018 workshop:
Full command history from the October 19 2018 workshop: