USEFUL COMMAND
1.CTRL+C stop MATLAB(the most powerful one)
2.quit&exit close MATLAB down completely
3.clc clear screen
4.clear clear workspace
5.↑ repeat previous command
6.scienticfic notation e.g. 4.5689e+12=4.5689*10^12
7.save save all the information(in matlab.mat)
8.load get all variables back when restart MATLAB
9.whos show all variables and all the information about it
10.who the name of the varieties
11.help
12.format loose extend the space between the lines
format compact let the space between lines colse
format long scaled fix point format with 15 digits for double and 7 for single
format short caled fix point format with 5 digits
13.lookfor search information or words
14.doc comes out document
15.pause(seconds) MATLAB will pause for seconds
16.dbquit quit the debuggingjava
PLOT
1.plot( ) draw the picture {plot( , ) first element stand for X, second for Y;or plot(h1,vi,h2,v2)}
if we want to change the color and the line.Just put: >> plot(h,v,' colorline')
2.hold on the second picture together with the first one in the same figure
3.hold off the second picture covers the first one
4.ylabel(' ') give y axis name
5.title(' ') give picture a title
6.axis([x,y,p,q,]) change the axis of a picture.X stand for left(min)in horizontal(x axis);Y means right in x;P is lower number in y;Q upper in y.**
7.bar(x,y) draw column diagram
8.pie([x,y]) draw pie chart
9.figure or figure( ) subspace to create a new chart
10.close all(NO.) close all the figure of NO figure
11.imread('name of file') load photo into MATLAB
or NAME=imread('name of file') load photo into MATLAB meanwhile name it
10.image(NAME) got the picture
12.axis off the axis will disappear
13.grid have grids in the picture put in 'grid' for twice,will get grid off
14.legend note the each separate plot in the figure
15.close( ) to close the figure,or use 'close all' to close allgit
MATRIX
1.[ ] want a vector.Empty means zero vector
2.semicolon the end of a row,start of another row
3.size( ) the size of matrix. E.g a X by Y matrix
4.matrixname(P,Q) the element in row P,line Q
matrixname(P,Q:O) same row,multiply coloms
matrixname(p,[Q,O]) P row,colom Q,O
matrixname(:) put all the elements of the matrix into a colomn(remove other colomns below the first colomn)
ABB: " : "can also means "1:end".That is,from the first to the endapi
*If you want to create a function quickly.just like if we want a 3by4 matrix whose elements are all zero.We can just put : zeros(3,4)app
notice,if zeros(4),we can get a 4by4 if we want 4by4 fives,just put 5*ones(4)
*If we want a diagonal function,just put diag([numbers])less
FUNCTION
1.rand create a number randomly between 0 to 1 rand(X,Y)-X by Y matrix
2.randi random integer
3.rann normal distribution
4.rng start random number at any position rng()
4.fix only concerve the integer,get rid of fraction fix()
>>>we can create our own function,which will just like the earlier function.Just use the editor,put in
"function functionname(input arguments)
function content;
end "
then we save the untitled editor,just name it the function name
>>>functin declaration:
function [out1,out2...]=functionname(input1,input2...)
>>>only the first function in editor called main function,below are all subfunctions.Main functions can be used in command window or other functions directly,however,subfunction can only be used by its main function
>>>local variable:accessable in only one function
>>>global variable:can be used in command window outside the function.Just add
"global variablename;"
BUT ATTENTION,do not use global variable easily
5.input must be a string,so have to type something inside single quotes.Morever add ":"to add numbers
6.fprintf(' n') pringts its string to the command windowdom
\n always stand for ending a line and start a new line
7.nargin returns the number of actual input functions that the function was called with
8.nargout returns the number of output arguments that the function caller requested
9.Robust function check function and provide error message
10.isscalar check whether is a scalar,turn out true or false
11.persistent variable a local variable that value keep unchanged(clear function to 0)ide
ALGORITHM
1.sqrt squart root
2.sind sine function in the unit of degree.Meanwhile sine function in radian just sin( )oop
4.O:P start from O to P,increse by 1 (same as function colon(O,P))
5.addition we can simply use O+P,or,use function form plus(O,P)ui
RULES FOR VARIABLES
1.only digits,underline,capital are allowed(capital in different places indicate different variable).
2.variables can't start with underline or digits.
3.the length is controled.Can't be more than 63 characters.idea
NOTATION
1.semicolon not showing the result
2.comma symble continue other commands,while showing result after the whole line is finished.
Also in functions,arguments(參數) should surrounded by parenthesis(括號),and seperated by comma
In operandes(運算符),arguments should be separated by operandes themselives.
E.g. Plus(1,2)=1+2
STATEMENT use==
1.Seclection if-else-ststement (elseif)
2.return quits the function and ignore all the statement following when facing errors
3.break calls the loop to quit immideately(only appears in loop)
4.continue moves to the next iteration
KEYWORDS
1.end the last index
2.return quits the function and ignore all the statement following when facing errors
EXTENSION OF C(java) language
%% start a new section
PRECEDENCE FROM HELP (lower number,higher execution)
1. parentheses () 2. transpose (.'), power (.^), complex conjugate transpose ('), matrix power (^) 3. power with unary minus (.^-), unary plus (.^+), or logical negation (.^~) as well as matrix power with unary minus (^-), unary plus (^+), or logical negation (^~) 4. unary plus (+), unary minus (-), logical negation (~) 5. multiplication (.*), right division (./), left division (.\), matrix multiplication (*), matrix right division (/), matrix left division (\) 6. addition (+), subtraction (-) 7. colon operator (:) 8. less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=) 9. element-wise logical AND (&) 10. element-wise logical OR (|) 11. short-circuit logical AND (&&) 12. short-circuit logical OR (||)
MATLAB default the association that from left to right when operators have the same precedence
RELATIONAL OPERATIORS
is greater than
= is greater than or equal to
the result 0 means fault, 1 means true
LOGICAL OPERATORS logical values:
In array multiplication
just use single & for and, single | for or
COMMENT
comment is the extra text that is not part of the code
anything after % is comment until the end of line
can use as help just like build-in function
BUSY MESSAGE AT THE LEFT BOTTOM,IF YOU SEE THAT,MEANS UR MATLAB IS NOT DEAD.REFERENCE:MATLAB GETSTART DOCUMENTIntroduction to Programming with MATLAB from Vanderbilt University Akos Ledeczi available in coursera