summaryrefslogtreecommitdiffhomepage
path: root/matlab.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'matlab.html.markdown')
-rw-r--r--matlab.html.markdown23
1 files changed, 20 insertions, 3 deletions
diff --git a/matlab.html.markdown b/matlab.html.markdown
index ad42d9a9..ddc0cb40 100644
--- a/matlab.html.markdown
+++ b/matlab.html.markdown
@@ -15,6 +15,7 @@ If you have any feedback please feel free to reach me at
[osvaldo.t.mendoza@gmail.com](mailto:osvaldo.t.mendoza@gmail.com).
```matlab
+%% Code sections start with two percent signs. Section titles go on the same line.
% Comments start with a percent sign.
%{
@@ -72,7 +73,7 @@ c = exp(a)*sin(pi/2) % c = 7.3891
% Calling functions can be done in either of two ways:
% Standard function syntax:
-load('myFile.mat', 'y') % arguments within parantheses, spererated by commas
+load('myFile.mat', 'y') % arguments within parentheses, separated by commas
% Command syntax:
load myFile.mat y % no parentheses, and spaces instead of commas
% Note the lack of quote marks in command form: inputs are always passed as
@@ -123,6 +124,7 @@ x(2:end) % ans = 32 53 7 1
x = [4; 32; 53; 7; 1] % Column vector
x = [1:10] % x = 1 2 3 4 5 6 7 8 9 10
+x = [1:2:10] % Increment by 2, i.e. x = 1 3 5 7 9
% Matrices
A = [1 2 3; 4 5 6; 7 8 9]
@@ -205,6 +207,8 @@ transpose(A) % Transpose the matrix, which is the same as:
A one
ctranspose(A) % Hermitian transpose the matrix
% (the transpose, followed by taking complex conjugate of each element)
+A' % Concise version of complex transpose
+A.' % Concise version of transpose (without taking complex conjugate)
@@ -254,6 +258,8 @@ axis equal % Set aspect ratio so data units are the same in every direction
scatter(x, y); % Scatter-plot
hist(x); % Histogram
+stem(x); % Plot values as stems, useful for displaying discrete data
+bar(x); % Plot bar graph
z = sin(x);
plot3(x,y,z); % 3D line plot
@@ -273,7 +279,7 @@ clf clear % clear current figure window, and reset most figure properties
% Properties can be set and changed through a figure handle.
% You can save a handle to a figure when you create it.
-% The function gcf returns a handle to the current figure
+% The function get returns a handle to the current figure
h = plot(x, y); % you can save a handle to a figure when you create it
set(h, 'Color', 'r')
% 'y' yellow; 'm' magenta, 'c' cyan, 'r' red, 'g' green, 'b' blue, 'w' white, 'k' black
@@ -400,7 +406,7 @@ exp(x)
sqrt(x)
log(x)
log10(x)
-abs(x)
+abs(x) %If x is complex, returns magnitude
min(x)
max(x)
ceil(x)
@@ -411,6 +417,14 @@ rand % Uniformly distributed pseudorandom numbers
randi % Uniformly distributed pseudorandom integers
randn % Normally distributed pseudorandom numbers
+%Complex math operations
+abs(x) % Magnitude of complex variable x
+phase(x) % Phase (or angle) of complex variable x
+real(x) % Returns the real part of x (i.e returns a if x = a +jb)
+imag(x) % Returns the imaginary part of x (i.e returns b if x = a+jb)
+conj(x) % Returns the complex conjugate
+
+
% Common constants
pi
NaN
@@ -465,6 +479,9 @@ median % median value
mean % mean value
std % standard deviation
perms(x) % list all permutations of elements of x
+find(x) % Finds all non-zero elements of x and returns their indexes, can use comparison operators,
+ % i.e. find( x == 3 ) returns indexes of elements that are equal to 3
+ % i.e. find( x >= 3 ) returns indexes of elements greater than or equal to 3
% Classes