"Data type, format, display" 1==2ans = 0%false1==1ans = 1%true1~=2ans = 11&&0ans = 01| | 0ans = 1xor (1,0) ans = 1%yihuoa=pi; Percent plus a semicolon will not be displayed in time a% direct display adisp (a)% ibid. default short 4 decimal disp (sprintf ('%0.2f ', a)) 3.14 control formats Format Longaa = 3.14159265358979 "Matrix construction" a= [1 2;3 4;5 6]% Matrix v=[1 2 3]% vector V=[1:0.1:2]% from 1 to 2 every 0.1 takes a number to become a row of vectors v=1:6% default takes 1 to 6 integers ones (2,3)% generates an all 1 2*3 matrix c=2*ones (2,3)% generated A total of 2 zeros (2,3)% of all 0 2*3 Matrix eye (4)% of the four-order unit matrix rand (3)% randomly generated 3*3 matrix rand (2,3)% random 2*3 matrix, each value between 0 to 1 randn (2,3)% Normal distribution (normally distributed) random value with a mean of 0hist (W)% plot W distribution histogram hist (w,50)% 50 histogram help command name can display the use of the command "matrix read" A=[1 2;3 4;5 6]a (3,2)% 3 row 2 column corresponding value A (2,:)% of all elements of line 2nd a (:, 2) of all elements of the 2nd column A ([1 3],:) the 1th and 3rd rows of all elements a (:, 2) =[10;11;12]% to A's 2nd column Assignment a=[a,[100;101;102]]% to a plus a column a (:)% Put all the elements of a in a row c=[a B]% directly around the two matrices of the adjacent spaces and commas equivalent c=[a; B]% connect two matrices up and down "properties of the Matrix" sz = size (A) SZ = 3 2 Returns the rows and columns of the matrix size (sz) ans = 1 2 above 3 2 is a 1 row 2 column matrix size (a,1) ans = 3size (a,2) ans = 2 Returns the size of a 1th/2 D v=[1 2 3 4]length (v) ans = 4length (A) ans = 3%length () Return rows and columns in the larger one "file path operation" PWD% current path CD ' C:\Users\ty\Desktop '% change Path ls% Desktop file load FeatuResX.dat% read in the file load (' FeaturesX.dat ')% ibid featuresx% file name represents now this file variable can directly display who% current all variables whos% current variable details v=featuresx (1:10)% Save the first 10 elements of the featuresx to Vsave Hello.mat v this variable into the Hello.mat file in the default path save Hello.txt-ascii% in ASCII to save the TXT file "Matrix operation" A*b% matrix multiplication A. *b% multiplication of each corresponding number in the matrix and so on Division square log (v)% of V does not have a number of logexp (v)% of V in each of the number of the e-base of the power operation ABS (v)% for each number of absolute sum (v)% sum sum (a,1)% of a per A column sum sum (a,2)% each row sum prod (a)% product product floor (a)% rounding ceil (a)% rounding up-v = -1*vv+1% v Each number +1a '%a transpose Matrix PINV (a)% The inverse matrix of a val=max (v)% v The largest number if V is a matrix, Max asks for the maximum value of each column of the matrix [Cal,ind]=max (v)% returns the maximum and maximum index Max (a) = max (a,[],1)% a matrix 1th dimension maximum, That is, the maximum value of each column is returned MAX (a,[],2)% A matrix The maximum value of the 2nd dimension, that is, return the maximum value of each row a<3% returns a 01 matrix that is the same size as a, represents the value of the position <3magic (3)% returns a 3*3 matrix, each row per column per The values of the diagonal are equal [R,c]=find (a>=7) r= ... c= ...% returns the row and column of a value greater than or equal to 7 in a "paint" t = [0:0.01:0.98];y1 = sin (2*pi*4*t);p lot (t,y1) % T for the argument drawing y2 = cos (2*pi*4*t) Hold on% keep the front picture unchanged plot (t,y2, ' r ')% on the basis of the draw Y2 curve, color for ' R ' Xlabel (' time ')% to x dimension Add ' time ' ylabel (' value ')% to y dimension Plus ' ValuE ' legend (' sin ', ' cos ')% plus two curves called ' sin ' cos ' title (' Myplot ')% plus title print-dpng ' myplot.png '% save the image as ' myplot.png ' in the default path ' Close% off image (if Save appears also deleted) figure (1); Plot (t,y1); figure (2); Plot (t,y2); % at this time there are two image files subplot (1,2,1); % 1*2 of two areas, using the first area plot (T,Y1); The Y1 image subplot (1,2,2) appears in the first lattice at this time; % using the second area plot (t,y2); % The Y2 image appears in the second lattice axis ([0.5 1-1 1])% changed the coordinates of the image, four numbers correspond to Minx Maxx Miny MAXYCLF% will draw all clear a=magic (A) I Magesc (a)% draws a 5*5 color lattice chart different color corresponding matrix in different values Imagesc (a), Colorbar, ColorMap Gray; The% comma-delimited command runs the color shades in turn to represent the different values of the "conditional statement" for I=1:10, V (i) =2^i; % indent only for good-looking, the amount of space does not affect the end; % Each statement end must be endindices=1:10;for i=indices,end; % and above equivalent while i<=5, I=i+1;end;while true, i=i+1; If i==6, Brek; End;end;if V (1) ==1, disp (' value is 1. '); ElseIf V (1) ==2, disp (' value is 2. '); Else disp (' not 1 or 2. '); end; function functions [y1,y2] = square (x)% equals sign preceded by the return value, can be more than one y1=x^2% equals sign is the function name, must match the file name, in parentheses is the parameter Y2=x^3[a,b]=squa Re (5) % The function in the current directory to call a = 25b = 125% To add another path, use will automatically search the current path and the added path, you can not switch the current path of Addpath (' C:\Users\ty\Desktop ')
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MATLAB Quick Start, most commonly used basic functions Daquan.