Professional Documents
Culture Documents
Basic commands Running script files and capturing output Matrix manipulations Plotting
Matlab Hints
Matlab is available on the EGR, and most other, computers on campus Icon:
MATLAB 6.5.lnk
Matlab Commands
pwd ls cd edit help command
See also webpage links and Appendix E of the EGR 220 text
Matlab Hints
Include comments!!
Header
Filename Assignment and brief description Your name and date
Comments throughout
% is used to indicate a comment line The semicolon tells Matlab not to echo the information on the given line to the screen
Analysis by Inspection
Ohms law V = IR RI = V
Rkk = sum of R in mesh k Rjk = negative sum of R in common between meshes j and k
R = [ 12 -2 -2 0 -1
7 -1
V = [6 -8 2]';
% There is no ; here
Running MatlabSample1.m
Run your script (.m) file in Matlab
Once it does what you want, record your results
>> diary Sample1Out.txt >> MatlabSample1 I= 0.3291 -1.0256 0.1624 i= 1.1880 >> diary off
Vector
An m x 1 array, or A 1 x n array
Matrix Multiplication
Standard matrix multiplication
A*B
Element-wise multiplication
Do Not mistake this for matrix multiplication A .* B
>> C = B * A C = 3 3 3 3 >> D = B .* A ??? Error using ==> .* Matrix dimensions must agree. >> D = B(:,1:2) .* A(1:2,:) D = 1 1 1 1
Plotting
2-D plots
Input or create x- and y- axis data sets plot (x, y, b--) Also contour(), based on x, y, z data
3-D plots
Input or create x-, y- and z- axis data sets mesh (x, y, z) Or, setup x- and y-axes with meshgrid() Also: surf()
Plotting
Scale axes with axis() command To create time step data for x-axis
t = [start-value: step-size: end-value]
1.5 4.5
2.0 5.0
2.5
For plotting more than one line hold and hold off can be useful