# ### Site Tools

public:matlab:matlab_crash_course

# Differences

This shows you the differences between two versions of the page.

 public:matlab:matlab_crash_course [2014/07/28 13:11]admin public:matlab:matlab_crash_course [2014/07/28 13:19] (current)admin [Matlab Crash Course] Both sides previous revision Previous revision 2014/07/28 13:19 admin [Matlab Crash Course] 2014/07/28 13:11 admin 2014/06/20 09:51 admin created 2014/07/28 13:19 admin [Matlab Crash Course] 2014/07/28 13:11 admin 2014/06/20 09:51 admin created Line 5: Line 5: {{ :​public:​matlab:​matlab_overview.jpg?​500 |Matlab window overview}} {{ :​public:​matlab:​matlab_overview.jpg?​500 |Matlab window overview}} - Some important example commands are shown in Table below. + Some important example commands are shown in the following ​Table: - + + ^ Command ^ Explanation ^ + | a=5; | Assign 5 to the variable a (semicolon supresses command window output) | + | a=[1,​2,​3,​4,​5];​ | Define a row vector (equal: a=1:5;) | + | a=[1,​2,​3,​4,​5]';​ | Define a column vector (' transposes a matrix) | + | b=rand(20,​30);​ | Define 20x30 matrix with random numbers between 0 and 1 | + | a=b(3:​5,​4:​10);​ | Take row 3,4,5 and columns 4 to 10 from matrix b and assign it to a (a will be a 3x7 matrix) | + | for k=1:​size(a,​2) ​ c(k)=a(1,​k)*4;​ end | For-loop from 1 to 7 where values of a (row 1) are multiplied by 4 and assigned to c | + | c=a(1,:)*4; | The same operation as above but more efficient | + | x=0:​0.01:​4*pi;​~y=sin(x);​ | Create vector x from 0 to $4\pi$ with increment 0.01 and a vector y containing the corresponding sine values | + | plot(x,​y,'​-.bx'​);​ | Plots x versus y with a blue (b), dash-dot (-.) line and crosses (x) as markers | + | save('​../​vars/​myVars.mat',​ '​a',​ '​b',​ '​c'​) | Saves the variables a, b and c to a .mat file in ../vars/ | + | load('​../​vars/​myVars.mat'​) | Restores variables a, b and c to Workspace | ===== Interface (GUIDE) ===== ===== Interface (GUIDE) ===== 