diff options
Diffstat (limited to 'matlab.html.markdown')
| -rw-r--r-- | matlab.html.markdown | 27 | 
1 files changed, 22 insertions, 5 deletions
| diff --git a/matlab.html.markdown b/matlab.html.markdown index 4d97834c..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 @@ -262,7 +268,7 @@ pcolor(A) % Heat-map of matrix: plot as grid of rectangles, coloured by value  contour(A) % Contour plot of matrix  mesh(A) % Plot as a mesh surface -h = figure	% Create new figure object, with handle h +h = figure % Create new figure object, with handle h  figure(h) % Makes the figure corresponding to handle h the current figure  close(h) % close figure with handle h  close all % close all open figure windows @@ -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 @@ -460,11 +474,14 @@ length  % length of a vector  sort    % sort in ascending order  sum     % sum of elements  prod    % product of elements -mode	% modal value +mode    % modal value  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 | 
