Matlab Programming For Beginners
Matlab Programming For Beginners
Function Handling
function [A,M,D] = Arith(a,b) A = a+b; M = a*b; D = a/b; end To take the output arguments [A,M,D] = Arith(10,5) Else [A,M,D] = Arith(a,b) a & b should be assigned with values
Relational Operators
Compares two numbers Returns 1 if the statement is true, 0 otherwise If the operands are matrices they should be in same
size. A new matrix of same size will be created and 1 or 0 will be assigned depending on the expression evaluated on each elements Eg . 5< 8, returns 1 Can be used in flow control
Relational Operators
< > <= >= == ~=
Less than Greater than Less than or equal Greater than or equal Equal Not eqaul
Logical Operators
Logical operators have two types of operators True or False Nonzero numbers are true and zero is false These operators can also be used in flow control & | ~
And OR NOT
Bit-wise functions
Operates on binary representation of the number bitand(A,B) Ex. Bitand(2,1) = and(10,01) = 00 = 0 bitor(A,B) Ex. Bitor(3,1) = or(11,01) = 11 = 3 Bitxor(A,B) Ex. Bitor(3,1) = or(11,01) = 11 = 3
Conditional Statements
if-else if conditional expression ....... . . end
Conditional Statements
if-else-end if conditional expression . . . else . . end
Conditional Statements
if-elseif-else-end
if conditional expression .. .. elseif conditional expression . . esleif conditional expression . . else . end
Conditional Statements
switch-case
Loops
For loop
nested For each if, case, for and while statements there should be corresponding end statements.
for i = 1:n for j = 1:m x(i,j); end end