![]() % You can save a handle to a figure when you create it. ![]() % while 'hold' is on, commands add to existing graph rather than replacing it plot ( x, y ) hold on plot ( x, z ) hold off loglog ( x, y ) % A log-log plot semilogx ( x, y ) % A plot with logarithmic x-axis semilogy ( x, y ) % A plot with logarithmic y-axis fplot x ) x^ 2, ) % plot the function x^2 from x=2 to x=5 grid on % Show grid turn off with 'grid off' axis square % Makes the current axes region square 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 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 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 close % close current figure window shg % bring an existing graphics window forward, or create new one if needed clf clear % clear current figure window, and reset most figure properties % Properties can be set and changed through a figure handle. 1 y = sin ( x ) plot ( x, y ) xlabel ( 'x axis' ) ylabel ( 'y axis' ) title ( 'Plot of y = sin(x)' ) axis () % x range from 0 to 2*pi, y range from -1 to 1 plot ( x, y1, '-', x, y2, '-', x, 圓, ':' ) % For multiple functions on one plot legend ( 'Line 1 label', 'Line 2 label' ) % Label curves with a legend % Alternative method to plot multiple functions in one plot. ![]() 10 : 2 * pi % Creates a vector that starts at 0 and ends at 2*pi with increments of. exp ( A ) % exponentiate each element expm ( A ) % calculate the matrix exponential sqrt ( A ) % take the square root of each element sqrtm ( A ) % find the matrix whose square is A % Plotting x = 0. * B % Multiply each element in A by its corresponding element in B % There are several pairs of functions, where one acts on each element, and % the other (whose name ends in m) acts on the whole matrix. For example: A * B % Matrix multiplication A. When preceded % by a period, they act on each element instead. Matrix Arithmetic % On their own, the arithmetic operators act on whole matrices. ' % Concise version of transpose (without taking complex conjugate) ctranspose ( A ) % Hermitian transpose the matrix, which is the same as: A ' % Concise version of complex transpose % (the transpose, followed by taking complex conjugate of each element) % Element by Element Arithmetic vs. x = 1 3 5 7 9 % Matrices A = % Rows are separated by a semicolon elements are separated with space or comma % A = % 1 2 3 % 4 5 6 % 7 8 9 A ( 2, 3 ) % ans = 6, A(row, column) A ( 6 ) % ans = 8 % (implicitly concatenates columns into vector, then indexes into that) A ( 2, 3 ) = 42 % Update row 2 col 3 with 42 % A = % 1 2 3 % 4 5 42 % 7 8 9 A ( 2 : 3, 2 : 3 ) % Creates a new matrix from the old one %ans = % 5 42 % 8 9 A (:, 1 ) % All rows in column 1 %ans = % 1 % 4 % 7 A ( 1 ,:) % All columns in row 1 %ans = % 1 2 3 % Concatenation of matrices (vertically) %ans = % 1 2 3 % 4 5 42 % 7 8 9 % 1 2 3 % 4 5 42 % 7 8 9 % this is the same as vertcat ( A, A ) % Concatenation of matrices (horizontally) %ans = % 1 2 3 1 2 3 % 4 5 42 4 5 42 % 7 8 9 7 8 9 % this is the same as horzcat ( A, A ) A (:, ) % Rearrange the columns of original matrix %ans = % 3 1 2 % 42 4 5 % 9 7 8 size ( A ) % ans = 3 3 A ( 1, :) = % Delete the first row of the matrix A (:, 1 ) = % Delete the first column of the matrix transpose ( A ) % Transpose the matrix, which is the same as: A. e = false % Vectors x = x ( 2 ) % ans = 32, indices in MATLAB start 1, not 0 x ( 2 : 3 ) % ans = 32 53 x ( 2 : end ) % ans = 32 53 7 1 x = % Column vector x = % x = 1 2 3 4 5 6 7 8 9 10 x = % Increment by 2, i.e. %% Code sections start with two percent signs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |