edit lecture-3.m
edit lecture3.m
lecture3
ans =
3.141592653589793
ans =
6.283185307179586
lecture3
ans =
9.424777960769379
edit matrix.m
pwd
ans =
/Users/pauldj/works/courses/LSC/LSC-18/m
M(4)
{Undefined function or variable 'M'.
}
matrix(4)
ans =
1 1 1 1 2 2 2 2
1 1 1 1 2 2 2 2
1 1 1 1 2 2 2 2
1 1 1 1 2 2 2 2
3 3 4 4 4 4 5 5
3 3 4 4 4 4 5 5
3 3 4 4 4 4 5 5
3 3 4 4 4 4 5 5
matrix(8)
ans =
Columns 1 through 14
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
3 3 3 3 4 4 4 4 4 4 4 4 5 5
Columns 15 through 16
2 2
2 2
2 2
2 2
2 2
2 2
2 2
2 2
5 5
5 5
5 5
5 5
5 5
5 5
5 5
5 5
matrix(6)
ans =
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
[ ones(1,5); ones(1,4) ]
{Error using vertcat
Dimensions of matrices being concatenated are not consistent.
}
[a,b,c,d] = lu(
[a,b,c,d] = lu(
|
{Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
}
matrix(6)
tmp =
36
ans =
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
1 1 1 1 1 1 2 2 2 2 2 2
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
3 3 3 4 4 4 4 4 4 5 5 5
edit matrixV.m
size([1 2 3 4])
ans =
1 4
length([1 2 3 4])
ans =
4
matrixV([ones(1,4)])
{Error using *
Inner matrix dimensions must agree.
Error in matrixV (line 8)
y = [ ones(n) * vTop + 2 * ones(n) * vBottom ;
}
matrixV([ones(4,1)])
ans =
6
6
16
16
matrixV([ones(6,1)])
[Warning: Integer operands are required for colon operator when used as index]
[> In matrixV (line 8)]
{Error using ones
Size inputs must be integers.
Error in matrixV (line 8)
y = [ ones(n) * vTop + 2 * ones(n) * vBottom ;
}
matrixV([ones(6,1)])
n =
3
vTop =
1
1
1
vBottom =
1
1
1
[Warning: Integer operands are required for colon operator when used as index]
[> In matrixV (line 8)]
{Error using ones
Size inputs must be integers.
Error in matrixV (line 8)
y = [ ones(n) * vTop + 2 * ones(n) * vBottom ;
}
matrixV([ones(6,1)])
n =
3
vTop =
1
1
1
vBottom =
1
1
1
[Warning: Integer operands are required for colon operator when used as index]
[> In matrixV (line 8)]
{Error using ones
Size inputs must be integers.
Error in matrixV (line 8)
y = [ ones(n) * vTop + 2 * ones(n) * vBottom ; ...
}
matrixV([ones(6,1)])
n =
3
vTop =
1
1
1
vBottom =
1
1
1
help odd
odd not found.
Use the Help browser search field to search the documentation, or
type "help help" for help command options, such as help for methods.
help elmat
Elementary matrices and matrix manipulation.
Elementary matrices.
zeros - Zeros array.
ones - Ones array.
eye - Identity matrix.
repmat - Replicate and tile array.
linspace - Linearly spaced vector.
logspace - Logarithmically spaced vector.
freqspace - Frequency spacing for frequency response.
meshgrid - X and Y arrays for 3-D plots.
accumarray - Construct an array with accumulation.
: - Regularly spaced vector and index into matrix.
Basic array information.
size - Size of array.
length - Length of vector.
ndims - Number of dimensions.
numel - Number of elements.
disp - Display matrix or text.
isempty - True for empty array.
isequal - True if arrays are numerically equal.
isequaln - True if arrays are numerically equal, treating NaNs as equal.
Matrix manipulation.
cat - Concatenate arrays.
reshape - Reshape array.
diag - Diagonal matrices and diagonals of matrix.
blkdiag - Block diagonal concatenation.
tril - Extract lower triangular part.
triu - Extract upper triangular part.
fliplr - Flip matrix in left/right direction.
flipud - Flip matrix in up/down direction.
flip - Flip the order of elements.
rot90 - Rotate matrix 90 degrees.
: - Regularly spaced vector and index into matrix.
find - Find indices of nonzero elements.
end - Last index.
sub2ind - Linear index from multiple subscripts.
ind2sub - Multiple subscripts from linear index.
bsxfun - Binary singleton expansion function.
Multi-dimensional array functions.
ndgrid - Generate arrays for N-D functions and interpolation.
permute - Permute array dimensions.
ipermute - Inverse permute array dimensions.
shiftdim - Shift dimensions.
circshift - Shift array circularly.
squeeze - Remove singleton dimensions.
Array utility functions.
isscalar - True for scalar.
isvector - True for vector.
isrow - True for row vector.
iscolumn - True for column vector.
ismatrix - True for matrix.
Special variables and constants.
eps - Floating point relative accuracy.
realmax - Largest positive floating point number.
realmin - Smallest positive floating point number.
intmax - Largest positive integer value.
intmin - Smallest integer value.
flintmax - Largest consecutive integer in floating point format.
pi - 3.1415926535897....
i - Imaginary unit.
inf - Infinity.
nan - Not-a-Number.
isnan - True for Not-a-Number.
isinf - True for infinite elements.
isfinite - True for finite elements.
j - Imaginary unit.
true - True array.
false - False array.
Specialized matrices.
compan - Companion matrix.
gallery - Test matrices.
hadamard - Hadamard matrix.
hankel - Hankel matrix.
hilb - Hilbert matrix.
invhilb - Inverse Hilbert matrix.
magic - Magic square.
pascal - Pascal matrix.
peaks - A sample function of two variables.
rosser - Classic symmetric eigenvalue test problem.
toeplitz - Toeplitz matrix.
vander - Vandermonde matrix.
wilkinson - Wilkinson's eigenvalue test matrix.
help elfun
Elementary math functions.
Trigonometric.
sin - Sine.
sind - Sine of argument in degrees.
sinh - Hyperbolic sine.
asin - Inverse sine.
asind - Inverse sine, result in degrees.
asinh - Inverse hyperbolic sine.
cos - Cosine.
cosd - Cosine of argument in degrees.
cosh - Hyperbolic cosine.
acos - Inverse cosine.
acosd - Inverse cosine, result in degrees.
acosh - Inverse hyperbolic cosine.
tan - Tangent.
tand - Tangent of argument in degrees.
tanh - Hyperbolic tangent.
atan - Inverse tangent.
atand - Inverse tangent, result in degrees.
atan2 - Four quadrant inverse tangent.
atan2d - Four quadrant inverse tangent, result in degrees.
atanh - Inverse hyperbolic tangent.
sec - Secant.
secd - Secant of argument in degrees.
sech - Hyperbolic secant.
asec - Inverse secant.
asecd - Inverse secant, result in degrees.
asech - Inverse hyperbolic secant.
csc - Cosecant.
cscd - Cosecant of argument in degrees.
csch - Hyperbolic cosecant.
acsc - Inverse cosecant.
acscd - Inverse cosecant, result in degrees.
acsch - Inverse hyperbolic cosecant.
cot - Cotangent.
cotd - Cotangent of argument in degrees.
coth - Hyperbolic cotangent.
acot - Inverse cotangent.
acotd - Inverse cotangent, result in degrees.
acoth - Inverse hyperbolic cotangent.
hypot - Square root of sum of squares.
Exponential.
exp - Exponential.
expm1 - Compute exp(x)-1 accurately.
log - Natural logarithm.
log1p - Compute log(1+x) accurately.
log10 - Common (base 10) logarithm.
log2 - Base 2 logarithm and dissect floating point number.
pow2 - Base 2 power and scale floating point number.
realpow - Power that will error out on complex result.
reallog - Natural logarithm of real number.
realsqrt - Square root of number greater than or equal to zero.
sqrt - Square root.
nthroot - Real n-th root of real numbers.
nextpow2 - Next higher power of 2.
Complex.
abs - Absolute value.
angle - Phase angle.
complex - Construct complex data from real and imaginary parts.
conj - Complex conjugate.
imag - Complex imaginary part.
real - Complex real part.
unwrap - Unwrap phase angle.
isreal - True for real array.
cplxpair - Sort numbers into complex conjugate pairs.
Rounding and remainder.
fix - Round towards zero.
floor - Round towards minus infinity.
ceil - Round towards plus infinity.
round - Round towards nearest integer.
mod - Modulus (signed remainder after division).
rem - Remainder after division.
sign - Signum.
help if
if Conditionally execute statements.
The general form of the if statement is
if expression
statements
ELSEIF expression
statements
ELSE
statements
END
The statements are executed if the real part of the expression
has all non-zero elements. The ELSE and ELSEIF parts are optional.
Zero or more ELSEIF parts can be used as well as nested if's.
The expression is usually of the form expr rop expr where
rop is ==, <, >, <=, >=, or ~=.
Example
if I == J
A(I,J) = 2;
elseif abs(I-J) == 1
A(I,J) = -1;
else
A(I,J) = 0;
end
See also relop, else, elseif, end, for, while, switch.
Reference page in Help browser
doc if
help exit
exit Exit from MATLAB.
exit terminates MATLAB after running finish.m, if finish.m exists.
It is the same as QUIT and takes the same termination options.
For more information, see the help for QUIT.
See also quit.
Reference page in Help browser
doc exit
help quit
quit Quit MATLAB session.
quit terminates MATLAB after running the script FINISH.M,
if it exists. The workspace information will not be saved
unless FINISH.M calls SAVE. If an error occurs while
executing FINISH.M, quitting is cancelled.
quit FORCE can be used to bypass an errant FINISH.M that
will not let you quit.
quit CANCEL can be used in FINISH.M to cancel quitting.
It has no effect anywhere else.
Example
Put the following lines of code in your FINISH.M file to
display a dialog that allows you to cancel quitting.
button = questdlg('Ready to quit?', ...
'Exit Dialog','Yes','No','No');
switch button
case 'Yes',
disp('Exiting MATLAB');
%Save variables to matlab.mat
save
case 'No',
quit cancel;
end
Note: When using Handle Graphics in FINISH.M make sure
to use UIWAIT, WAITFOR, or DRAWNOW so that figures are
visible.
See also exit.
Reference page in Help browser
doc quit
matrixV([ones(6,1)])
{Error: File: matrixV.m Line: 5 Column: 13
Unexpected MATLAB operator.
}
matrixV([ones(6,1)])
{Error: File: matrixV.m Line: 5 Column: 13
Unexpected MATLAB operator.
}
help ==
== Equal.
A == B does element by element comparisons between A and B
and returns a matrix of the same size with elements set to logical 1
where the relation is true and elements set to logical 0 where it is
not. A and B must have the same dimensions unless one is a
scalar. A scalar can be compared with any size array.
C = eq(A,B) is called for the syntax 'A == B' when A or B is an
object.
Other functions named eq
Reference page in Help browser
doc eq
doc eq
matrixV([ones(6,1)])
matrixV([ones(8,1)])
ans =
12
12
12
12
32
32
32
32
matrixV([ones(12,1)])
ans =
18
18
18
18
18
18
48
48
48
48
48
48
edit matrixVclever
matrixVclever([ones(12,1)])
{Error: File: matrixVclever.m Line: 7 Column: 27
Expression or statement is incomplete or incorrect.
}
matrixVclever([ones(12,1)])
y =
18
18
18
18
18
18
48
48
48
48
48
48
ans =
18
18
18
18
18
18
48
48
48
48
48
48
matrixVclever([ones(1,12)])
ans =
18
18
18
18
18
18
48
48
48
48
48
48
matrixVclever([ones(18,1)])
pwd
ans =
/Users/pauldj/works/courses/LSC/LSC-18/m
matrixVclever([ones(20,1)])
ans =
30
30
30
30
30
30
30
30
30
30
80
80
80
80
80
80
80
80
80
80
edit filter
edit myfilter
edit myfft
myfft
myfft
myfft
{Undefined function or variable 'pts'.
Error in myfft (line 7)
plot( pts, sig, 'o-' );
}
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
myfft
[Warning: Imaginary parts of complex X and/or Y arguments ignored]
[> In myfft (line 26)]
myfft
[Warning: Imaginary parts of complex X and/or Y arguments ignored]
[> In myfft (line 26)]
myfft
myfft
[Warning: Imaginary parts of complex X and/or Y arguments ignored]
[> In myfft (line 27)]
edit visit
help while
while Repeat statements an indefinite number of times.
The general form of a while statement is:
while expression
statements
END
The statements are executed while the real part of the expression
has all non-zero elements. The expression is usually the result of
expr rop expr where rop is ==, <, >, <=, >=, or ~=.
The BREAK statement can be used to terminate the loop prematurely.
For example (assuming A already defined):
E = 0*A; F = E + eye(size(E)); N = 1;
while norm(E+F-E,1) > 0,
E = E + F;
F = A*F/N;
N = N + 1;
end
See also for, if, switch, break, continue, end.
Reference page in Help browser
doc while
M = rand(5)
M = rand(5)
|
{Error: The input character is not valid in MATLAB statements or expressions.
}
M = rand(5)
M =
0.8147 0.0975 0.1576 0.1419 0.6557
0.9058 0.2785 0.9706 0.4218 0.0357
0.1270 0.5469 0.9572 0.9157 0.8491
0.9134 0.9575 0.4854 0.7922 0.9340
0.6324 0.9649 0.8003 0.9595 0.6787
visit(M)
visit(M)
visit(M)
ans =
0.8147
ans =
0.2785
ans =
0.9572
ans =
0.7922
ans =
0.6787
M = reshape( 1:36, 6, [] );
M
M =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
visit(M,1)
ans =
1
ans =
8
ans =
15
ans =
22
ans =
29
ans =
36
visit(M,2)
ans =
1 7
2 8
ans =
15 21
16 22
ans =
29 35
30 36
M
M =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
visit(M,3)
ans =
1 7 13
2 8 14
3 9 15
ans =
22 28 34
23 29 35
24 30 36
visit(M,4)
ans =
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
{Index exceeds matrix dimensions.
Error in visit (line 4)
M(1:b,1:b)
}
visit(M,4)
ans =
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
ans =
29 35
30 36
visit(M,5)
ans =
1 7 13 19 25
2 8 14 20 26
3 9 15 21 27
4 10 16 22 28
5 11 17 23 29
ans =
36
visit(M,7)
ans =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
diary