Mathematical operations of matrices:
Assumed:a is a matrix,m is a vector
Log (a)--a logarithm of each element
Exp (a)--base e index
1./a--The mentor of every element
[A,b]=max (m)--m is a vector,a is the largest element in m , andb is a ordinal number in m (from small to large row)
M<3--such as m=[1 6 7], will be [1 0 0](should be able to understand)
Find (m>3)--such as m=[1 6 7], will get [2 3], that is , the subscript of the element greater than 3 (should be able to understand)
Magic (3)--produces a 3*3 matrix, with each row added equal to each column .
[C,d]=find (A>3)--Finds all elements greater than 3 in the a matrix , andC returns rows ,D returns the column
SUM (m)--Sum
Prod (m)--Product
Floor (m)--Rounding down
Ceil (m)--Rounding up
Max (a,[],1)--Take the maximum value of each column
Max (a,[],2)--Take the maximum value of each row
Sum (a) or sum (a,1)--Sum each column
SUM (a,2)--sum each line
SUM (SUM (A.*eye (3))-- a matrix of the diagonal elements of A and (a is a 3*3 )
Max (A (:))--Find The largest element in a matrix
Flipud (a)--Flips The matrix up and down
SUM (SUM (A.*flipud (eye (3)))-- The sum of a pair of diagonal elements (a is 3*3 The Matrix)
Drawing:
Plot (x, y)-- is the dependent variable andy is the argument
On
Plot (x1,y1, ' R ')--Put the picture above the old figure, the color is red
Xlabel (")--Give the argument a name
Ylabel (")--Give the dependent variable a name
Legend (",")--Legend
How to save a picture in MATLAB:
1, You can use the print command to save:
Print (1, '-djpeg ', ' picname.jpeg ')
Note: The first parameter represents the handle number of the graphics window, the second argument, in quotation marks, is saved in the JPEG format, and the third parameter is the file name.
2, can be saved with the SaveAs command:
SaveAs (GCF, ' picname ', ' jpg ')
Note: The first parameter is the function name Matlab obtains the graphics handle number, the second parameter, in quotation marks is the file name that you want to save, do not write the suffix here, the third parameter is the file type.
3.Figure (1);p lot (); --Numbering the graph
In 4.matlab, subplot (m,n,p) can draw an mxn Sub-chart in a figure, P can specify the position of the sub-graph, in general P is a single number,p is a vector can be combined with multiple sub-graphs as a sub-graph.
- Clear
- Clc
- X=-4*pi+eps:0.01:4*pi;
- Y1=sin (x);
- Y2=cos (x);
- Y3=tan (x);
- Figure
- Subplot (2,2,1);p lot (x,y1), title (' Sin (x) ')
- Subplot (2,2,2);p lot (x,y2), title (' cos (x) ')
- Subplot (2,2,[3,4]);p lot (x,y3), title (' Tan (x) ')% merges two of the second row into one
- Figure
- Subplot (2,2,[1 2]);p lot (x,y1), title (' Sin (x) ')% merges two of the first row into one
- Subplot (2,2,3);p lot (x,y2), title (' cos (x) ')
- Subplot (2,2,4);p lot (x,y3), title (' Tan (x) ')
- Figure
- Subplot (2,2,[1 3]);p lot (x,y1); title (' Sin (x) ')% merge two of the first column into one
- Subplot (2,2,2);p lot (x,y2), title (' cos (x) ')
- Subplot (2,2,4);p lot (x,y3), title (' Tan (x) ')
- Figure
- Subplot (2,2,1);p lot (x,y1), title (' Sin (x) ')
- Subplot (2,2,3);p lot (x,y2), title (' cos (x) ')
- Subplot (2,2,[2 4]);p lot (x,y3), title (' Tan (x) ')% merges two of the second column into one
- 5.axis ([1 2 3 4]) --Set x axis is ( the ), y The axis range is set to ( 3 , 4)
5.axis ([1 2 3 4])--Set the x axis to (+) and they - axis range to (3 , 4 )
6.Imagesc (a)--Visual matrix
7.Imagesc (a), Colorbar,clolormap gray; --Black and white (amount, bad description, as below)
Machine Learning--octave Matrix operation (2)--day3