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.
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 tril
tril Extract lower triangular part.
tril(X) is the lower triangular part of X.
tril(X,K) is the elements on and below the K-th diagonal
of X . K = 0 is the main diagonal, K > 0 is above the
main diagonal and K < 0 is below the main diagonal.
See also triu, diag.
Overloaded methods:
gf/tril
codistributed/tril
gpuArray/tril
sym/tril
Reference page in Help browser
doc tril
doc
help plot
plot Linear plot.
plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, disconnected
line objects are created and plotted as discrete points vertically at
X.
plot(Y) plots the columns of Y versus their index.
If Y is complex, plot(Y) is equivalent to plot(real(Y),imag(Y)).
In all other uses of plot, the imaginary part is ignored.
Various line types, plot symbols and colors may be obtained with
plot(X,Y,S) where S is a character string made from one element
from any or all the following 3 columns:
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
For example, plot(X,Y,'c+:') plots a cyan dotted line with a plus
at each data point; plot(X,Y,'bd') plots blue diamond at each data
point but does not draw any line.
plot(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by
the (X,Y,S) triples, where the X's and Y's are vectors or matrices
and the S's are strings.
For example, plot(X,Y,'y-',X,Y,'go') plots the data twice, with a
solid yellow line interpolating green circles at the data points.
The plot command, if no color is specified, makes automatic use of
the colors specified by the axes ColorOrder property. By default,
plot cycles through the colors in the ColorOrder property. For
monochrome systems, plot cycles over the axes LineStyleOrder property.
Note that RGB colors in the ColorOrder property may differ from
similarly-named colors in the (X,Y,S) triples. For example, the
second axes ColorOrder property is medium green with RGB [0 .5 0],
while plot(X,Y,'g') plots a green line with RGB [0 1 0].
If you do not specify a marker type, plot uses no marker.
If you do not specify a line style, plot uses a solid line.
plot(AX,...) plots into the axes with handle AX.
plot returns a column vector of handles to lineseries objects, one
handle per plotted line.
The X,Y pairs, or X,Y,S triples, can be followed by
parameter/value pairs to specify additional properties
of the lines. For example, plot(X,Y,'LineWidth',2,'Color',[.6 0 0])
will create a plot with a dark red line width of 2 points.
Example
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
See also plottools, semilogx, semilogy, loglog, plotyy, plot3, grid,
title, xlabel, ylabel, axis, axes, hold, legend, subplot, scatter.
Overloaded methods:
phytree/plot
clustergram/plot
HeatMap/plot
channel.plot
sfit/plot
cfit/plot
iddata/plot
idnlhw/plot
idnlarx/plot
mpc/plot
frd/plot
dspdata.plot
LinearModel/plot
timeseries/plot
wdectree/plot
ntree/plot
dtree/plot
wvtree/plot
rwvtree/plot
edwttree/plot
Reference page in Help browser
doc plot
doc plot
j = -4
j =
-4
j = -4;
j = -4; h = 5;
j = -4, h = 5, z = 12
j =
-4
h =
5
z =
12
j = -4, h = 5; z = 12
j =
-4
z =
12
pi
ans =
3.141592653589793
format long
format short
pi
ans =
3.1416
format long
help format
format Set output format.
format with no inputs sets the output format to the default appropriate
for the class of the variable. For float variables, the default is
format SHORT.
format does not affect how MATLAB computations are done. Computations
on float variables, namely single or double, are done in appropriate
floating point precision, no matter how those variables are displayed.
Computations on integer variables are done natively in integer. Integer
variables are always displayed to the appropriate number of digits for
the class, for example, 3 digits to display the INT8 range -128:127.
format SHORT and LONG do not affect the display of integer variables.
format may be used to switch between different output display formats
of all float variables as follows:
format SHORT Scaled fixed point format with 5 digits.
format LONG Scaled fixed point format with 15 digits for double
and 7 digits for single.
format SHORTE Floating point format with 5 digits.
format LONGE Floating point format with 15 digits for double and
7 digits for single.
format SHORTG Best of fixed or floating point format with 5
digits.
format LONGG Best of fixed or floating point format with 15
digits for double and 7 digits for single.
format SHORTENG Engineering format that has at least 5 digits
and a power that is a multiple of three
format LONGENG Engineering format that has exactly 16 significant
digits and a power that is a multiple of three.
format may be used to switch between different output display formats
of all numeric variables as follows:
format HEX Hexadecimal format.
format + The symbols +, - and blank are printed
for positive, negative and zero elements.
Imaginary parts are ignored.
format BANK Fixed format for dollars and cents.
format RAT Approximation by ratio of small integers. Numbers
with a large numerator or large denominator are
replaced by *.
format may be used to affect the spacing in the display of all
variables as follows:
format COMPACT Suppresses extra line-feeds.
format LOOSE Puts the extra line-feeds back in.
Example:
format short, pi, single(pi)
displays both double and single pi with 5 digits as 3.1416 while
format long, pi, single(pi)
displays pi as 3.141592653589793 and single(pi) as 3.1415927.
format, intmax('uint64'), realmax
shows these values as 18446744073709551615 and 1.7977e+308 while
format hex, intmax('uint64'), realmax
shows them as ffffffffffffffff and 7fefffffffffffff respectively.
The HEX display corresponds to the internal representation of the value
and is not the same as the hexadecimal notation in the C programming
language.
See also disp, display, isnumeric, isfloat, isinteger.
Reference page in Help browser
doc format
pi
ans =
3.141592653589793
pi = 5.0
pi =
5
pi
pi =
5
sqrt(-1)
ans =
0.000000000000000 + 1.000000000000000i
i
ans =
0.000000000000000 + 1.000000000000000i
for i=1:10, pi=i, end
pi =
1
pi =
2
pi =
3
pi =
4
pi =
5
pi =
6
pi =
7
pi =
8
pi =
9
pi =
10
i
i =
10
j
j =
-4
help clear
clear Clear variables and functions from memory.
clear removes all variables from the workspace.
clear VARIABLES does the same thing.
clear GLOBAL removes all global variables.
clear FUNCTIONS removes all compiled MATLAB and MEX-functions.
clear ALL removes all variables, globals, functions and MEX links.
clear ALL at the command prompt also clears the base import list.
clear IMPORT clears the base import list. It can only be issued at the
command prompt. It cannot be used in a function.
clear CLASSES is the same as clear ALL except that class definitions
are also cleared. If any objects exist outside the workspace (say in
userdata or persistent in a locked program file) a warning will be
issued and the class definition will not be cleared. clear CLASSES must
be used if the number or names of fields in a class are changed.
clear JAVA is the same as clear ALL except that java classes on the
dynamic java path (defined using JAVACLASSPATH) are also cleared.
clear VAR1 VAR2 ... clears the variables specified. The wildcard
character '*' can be used to clear variables that match a pattern. For
instance, clear X* clears all the variables in the current workspace
that start with X.
clear -REGEXP PAT1 PAT2 can be used to match all patterns using regular
expressions. This option only clears variables. For more information on
using regular expressions, type "doc regexp" at the command prompt.
If X is global, clear X removes X from the current workspace, but
leaves it accessible to any functions declaring it global.
clear GLOBAL X completely removes the global variable X.
clear GLOBAL -REGEXP PAT removes global variables that match regular
expression patterns.
Note that to clear specific global variables, the GLOBAL option must
come first. Otherwise, all global variables will be cleared.
clear FUN clears the function specified. If FUN has been locked by
MLOCK it will remain in memory. Use a partial path (see PARTIALPATH) to
distinguish between different overloaded versions of FUN. For
instance, 'clear inline/display' clears only the INLINE method for
DISPLAY, leaving any other implementations in memory.
clear ALL, clear FUN, or clear FUNCTIONS also have the side effect of
removing debugging breakpoints and reinitializing persistent variables
since the breakpoints for a function and persistent variables are
cleared whenever the program file changes or is cleared.
Use the functional form of clear, such as clear('name'), when the
variable name or function name is stored in a string.
Examples for pattern matching:
clear a* % Clear variables starting with "a"
clear -regexp ^b\d{3}$ % Clear variables starting with "b" and
% followed by 3 digits
clear -regexp \d % Clear variables containing any digits
See also clearvars, who, whos, mlock, munlock, persistent, import.
Reference page in Help browser
doc clear
clear(pi)
{Error using clear
Argument must contain a string.
}
clear("pi")
clear("pi")
|
{Error: The input character is not valid in MATLAB statements or expressions.
}
clear('pi')
clear('i')
pi
ans =
3.141592653589793
i
ans =
0.000000000000000 + 1.000000000000000i
M=[1, 2, 3, 4]
M =
1 2 3 4
help who
who List current variables.
who lists the variables in the current workspace.
In a nested function, variables are grouped into those in the nested
function and those in each of the containing functions. who displays
only the variables names, not the function to which each variable
belongs. For this information, use WHOS. In nested functions and
in functions containing nested functions, even unassigned variables
are listed.
WHOS lists more information about each variable.
who GLOBAL and WHOS GLOBAL list the variables in the global workspace.
who -FILE FILENAME lists the variables in the specified .MAT file.
who ... VAR1 VAR2 restricts the display to the variables specified. The
wildcard character '*' can be used to display variables that match a
pattern. For instance, who A* finds all variables in the current
workspace that start with A.
who -REGEXP PAT1 PAT2 can be used to display all variables matching the
specified patterns using regular expressions. For more information on
using regular expressions, type "doc regexp" at the command prompt.
Use the functional form of who, such as who('-file',FILE,V1,V2),
when the filename or variable names are stored in strings.
S = who(...) returns a cell array containing the names of the variables
in the workspace or file. You must use the functional form of who when
there is an output argument.
Examples for pattern matching:
who a* % Show variable names starting with "a"
who -regexp ^b\d{3}$ % Show variable names starting with "b"
% and followed by 3 digits
who -file fname -regexp \d % Show variable names containing any
% digits that exist in MAT-file fname
See also whos, clear, clearvars, save, load.
Overloaded methods:
Simulink.who
Reference page in Help browser
doc who
help whos
whos List current variables, long form.
whos is a long form of WHO. It lists all the variables in the current
workspace, together with information about their size, bytes, class,
etc.
In a nested function, variables are grouped into those in the nested
function and those in each of the containing functions, each group
separated by a line of dashes. In nested functions and in functions
containing nested functions, even uninitialized variables are listed.
whos GLOBAL lists the variables in the global workspace.
whos -FILE FILENAME lists the variables in the specified .MAT file.
whos ... VAR1 VAR2 restricts the display to the variables specified.
The wildcard character '*' can be used to display variables that match
a pattern. For instance, whos A* finds all variables in the current
workspace that start with A.
whos -REGEXP PAT1 PAT2 can be used to display all variables matching
the specified patterns using regular expressions. For more information
on using regular expressions, type "doc regexp" at the command prompt.
Use the functional form of whos, such as whos('-file',FILE,V1,V2), when
the filename or variable names are stored in strings.
S = whos(...) returns a structure with the fields:
name -- variable name
size -- variable size
bytes -- number of bytes allocated for the array
class -- class of variable
global -- logical indicating whether variable is global
sparse -- logical indicating whether value is sparse
complex -- logical indicating whether value is complex
nesting -- struct with the following two fields:
function -- name of function where variable is defined
level -- nesting level of the function
persistent -- logical indicating whether variable is persistent
You must use the functional form of whos when there is an output
argument.
Examples for pattern matching:
whos a* % Show variable names starting with "a"
whos -regexp ^b\d{3}$ % Show variable names starting with "b"
% and followed by 3 digits
whos -file fname -regexp \d % Show variable names containing any
% digits that exist in MAT-file fname
See also who, clear, clearvars, save, load.
Overloaded methods:
Simulink.whos
Reference page in Help browser
doc whos
who('M')
Your variables are:
M
whos('M')
Name Size Bytes Class Attributes
M 1x4 32 double
M=[1; 2; 3; 4]
M =
1
2
3
4
whos('M')
Name Size Bytes Class Attributes
M 4x1 32 double
v = [1 2 3 4]
v =
1 2 3 4
v'
ans =
1
2
3
4
v'
ans =
1
2
3
4
v' * rand(4,4)
{Error using *
Inner matrix dimensions must agree.
}
v * rand(4,4)
ans =
2.993125505133373 4.187749025342196 4.625464538532768 3.909039601286396
M = [1 2; 3, 4]
M =
1 2
3 4
A = [M M]
A =
1 2 1 2
3 4 3 4
A = [1 2 3; 4 5 6]; B = [-1 -1; -2 -2];
C = [A B; B B B]
{Error using vertcat
Dimensions of matrices being concatenated are not consistent.
}
C = [A B zeros(2,1); B B B]
C =
1 2 3 -1 -1 0
4 5 6 -2 -2 0
-1 -1 -1 -1 -1 -1
-2 -2 -2 -2 -2 -2
rand(3)
ans =
0.602843089382083 0.117417650855806 0.424166759713807
0.711215780433683 0.296675873218327 0.507858284661118
0.221746734017240 0.318778301925882 0.085515797090044
rand(3,1)
ans =
0.262482234698333
0.801014622769739
0.029220277562146
rand(3,1,2)
ans(:,:,1) =
0.928854139478045
0.730330862855453
0.488608973803579
ans(:,:,2) =
0.578525061023439
0.237283579771521
0.458848828179931
rand(3,4,2)
ans(:,:,1) =
0.963088539286913 0.231594386708524 0.679135540865748 0.987982003161633
0.546805718738968 0.488897743920167 0.395515215668593 0.037738866239552
0.521135830804001 0.624060088173690 0.367436648544477 0.885168008202475
ans(:,:,2) =
0.913286827639239 0.261871183870716 0.136553137355370 0.653757348668560
0.796183873585212 0.335356839962797 0.721227498581740 0.494173936639270
0.098712278655574 0.679727951377338 0.106761861607241 0.779051723231275
help randn
randn Normally distributed pseudorandom numbers.
R = randn(N) returns an N-by-N matrix containing pseudorandom values drawn
from the standard normal distribution. randn(M,N) or randn([M,N]) returns
an M-by-N matrix. randn(M,N,P,...) or randn([M,N,P,...]) returns an
M-by-N-by-P-by-... array. randn returns a scalar. randn(SIZE(A)) returns
an array the same size as A.
Note: The size inputs M, N, P, ... should be nonnegative integers.
Negative integers are treated as 0.
R = randn(..., CLASSNAME) returns an array of normal values of the
specified class. CLASSNAME can be 'double' or 'single'.
R = randn(..., 'like', Y) returns an array of normal values of the
same class as Y.
The sequence of numbers produced by randn is determined by the settings of
the uniform random number generator that underlies RAND, randn, and RANDI.
randn uses one or more uniform random values to create each normal random
value. Control that shared random number generator using RNG.
Examples:
Example 1: Generate values from a normal distribution with mean 1
and standard deviation 2.
r = 1 + 2.*randn(100,1);
Example 2: Generate values from a bivariate normal distribution with
specified mean vector and covariance matrix.
mu = [1 2];
Sigma = [1 .5; .5 2]; R = chol(Sigma);
z = repmat(mu,100,1) + randn(100,2)*R;
Example 3: Reset the random number generator used by RAND, RANDI, and
randn to its default startup settings, so that randn produces the same
random numbers as if you restarted MATLAB.
rng('default');
randn(1,5)
Example 4: Save the settings for the random number generator used by
RAND, RANDI, and randn, generate 5 values from randn, restore the
settings, and repeat those values.
s = rng
z1 = randn(1,5)
rng(s);
z2 = randn(1,5) % z2 contains exactly the same values as z1
Example 5: Reinitialize the random number generator used by RAND,
RANDI, and randn with a seed based on the current time. randn will
return different values each time you do this. NOTE: It is usually
not necessary to do this more than once per MATLAB session.
rng('shuffle');
randn(1,5)
See Updating Your Random Number Generator Syntax to use RNG to replace
randn with the 'seed' or 'state' inputs.
See also rand, randi, rng, RandStream, RandStream/randn
Overloaded methods:
RandStream/randn
distributed/randn
codistributor2dbc/randn
codistributor1d/randn
codistributed/randn
gpuArray/randn
Reference page in Help browser
doc randn
zeros(4)
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
ones(5)
ans =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
eye(6)
ans =
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
1:24
ans =
Columns 1 through 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Columns 17 through 24
17 18 19 20 21 22 23 24
1:2:24
ans =
1 3 5 7 9 11 13 15 17 19 21 23
1:pi/12:pi
ans =
Columns 1 through 4
1.000000000000000 1.261799387799149 1.523598775598299 1.785398163397448
Columns 5 through 8
2.047197551196597 2.308996938995747 2.570796326794897 2.832595714594046
Column 9
3.094395102393195
1:24
ans =
Columns 1 through 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Columns 17 through 24
17 18 19 20 21 22 23 24
M = [1 2 3; 4 5 6; 7 8 9]
M =
1 2 3
4 5 6
7 8 9
diag(M)
ans =
1
5
9
diag([1 2 3])
ans =
1 0 0
0 2 0
0 0 3
diag(diag(M))
ans =
1 0 0
0 5 0
0 0 9
M * eye(3)
ans =
1 2 3
4 5 6
7 8 9
M .* eye(3)
ans =
1 0 0
0 5 0
0 0 9
M
M =
1 2 3
4 5 6
7 8 9
B = rand(3);
M / B
ans =
-3.507947441095616 4.804876571953198 -0.936055892057272
-3.962351571685273 9.650584479768664 -2.119379985531626
-4.416755702274931 14.496292387584131 -3.302704079005980
M ./ B
ans =
1.398528873826621 5.985102133870892 98.228783419999871
4.426146946947474 7.155677742352986 8.063711271287477
7.857024562712113 40.442884633339929 17.999192354992754
M
M =
1 2 3
4 5 6
7 8 9
M(1,2)
ans =
2
M(2,1)
ans =
4
M(1,4)
{Index exceeds matrix dimensions.
}
M(1,4) = 4
M =
1 2 3 4
4 5 6 0
7 8 9 0
M(4,4) = -1
M =
1 2 3 4
4 5 6 0
7 8 9 0
0 0 0 -1
M(6,6) = 10
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M(4,:)
ans =
0 0 0 -1 0 0
M(:,1)
ans =
1
4
7
0
0
0
M(:,-1)
{Subscript indices must either be real positive integers or logicals.
}
M(:,end-1)
ans =
0
0
0
0
0
0
M(:,end)
ans =
0
0
0
0
0
10
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M(1:3,1:3)
ans =
1 2 3
4 5 6
7 8 9
M(1:2:5,1:2:5)
ans =
1 3 0
7 9 0
0 0 0
M(1:2:end,1:2:end)
ans =
1 3 0
7 9 0
0 0 0
M(end:-2:1,1:2:end)
ans =
0 0 0
0 0 0
4 6 0
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M(1:2,:)
ans =
1 2 3 4 0 0
4 5 6 0 0 0
M([1 2],:)
ans =
1 2 3 4 0 0
4 5 6 0 0 0
[1 2]
ans =
1 2
1:2
ans =
1 2
M([1 2 1 1],:)
ans =
1 2 3 4 0 0
4 5 6 0 0 0
1 2 3 4 0 0
1 2 3 4 0 0
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M(2:3,2:3)
ans =
5 6
8 9
M(3:-2:1,3:-2:1)
ans =
9 7
3 1
M(.)
M(.)
|
{Error: Unexpected MATLAB operator.
}
M(:)
ans =
1
4
7
0
0
0
2
5
8
0
0
0
3
6
9
0
0
0
4
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
10
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M(9)
ans =
8
diag(M)
ans =
1
5
9
-1
0
10
diag(M,-1)
ans =
4
8
0
0
0
diag(M,+1)
ans =
2
6
0
0
0
diag(diag(M,-1),1)
ans =
0 4 0 0 0 0
0 0 8 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
diag(diag(M,-1),3)
ans =
0 0 0 4 0 0 0 0
0 0 0 0 8 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
M'
ans =
1 4 7 0 0 0
2 5 8 0 0 0
3 6 9 0 0 0
4 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M
M =
1 2 3 4 0 0
4 5 6 0 0 0
7 8 9 0 0 0
0 0 0 -1 0 0
0 0 0 0 0 0
0 0 0 0 0 10
M = rand(5)
M =
Columns 1 through 4
0.479922141146060 0.805489424529686 0.028674152464106 0.500471624154843
0.904722238067363 0.576721515614685 0.489901388512224 0.471088374541939
0.609866648422558 0.182922469414914 0.167927145682257 0.059618867579639
0.617666389588455 0.239932010568717 0.978680649641159 0.681971904149063
0.859442305646212 0.886511933076101 0.712694471678914 0.042431137500742
Column 5
0.071445464600642
0.521649842464284
0.096730025780867
0.818148553859625
0.817547092079286
M > .6
ans =
0 1 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 1 1 1
1 1 1 0 1
B = (M > .6)
B =
0 1 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 1 1 1
1 1 1 0 1
whos('B')
Name Size Bytes Class Attributes
B 5x5 25 logical
B(2,2)
ans =
0
B(2,2) = pi
B =
0 1 0 0 0
1 1 0 0 0
1 0 0 0 0
1 0 1 1 1
1 1 1 0 1
whos('B')
Name Size Bytes Class Attributes
B 5x5 25 logical
B * [1,2,3,4,5]'
ans =
2
3
1
13
11
B
B =
0 1 0 0 0
1 1 0 0 0
1 0 0 0 0
1 0 1 1 1
1 1 1 0 1
find(B == 1)
ans =
2
3
4
5
6
7
10
14
15
19
24
25
help linspace
linspace Linearly spaced vector.
linspace(X1, X2) generates a row vector of 100 linearly
equally spaced points between X1 and X2.
linspace(X1, X2, N) generates N points between X1 and X2.
For N = 1, linspace returns X2.
Class support for inputs X1,X2:
float: double, single
See also logspace, colon.
Overloaded methods:
distributed/linspace
codistributor2dbc/linspace
codistributor1d/linspace
codistributed/linspace
gpuArray/linspace
Reference page in Help browser
doc linspace
linspace( pi, 2*pi, 1 )
ans =
6.283185307179586
linspace( pi, 2*pi, 2 )
ans =
3.141592653589793 6.283185307179586
linspace( pi, 2*pi, 1 )
ans =
6.283185307179586
linspace( pi, 2*pi, 2 )
ans =
3.141592653589793 6.283185307179586
linspace( pi, 2*pi, 3 )
ans =
3.141592653589793 4.712388980384690 6.283185307179586
plot(linspace( pi, 2*pi, 3 ))
plot(sin(linspace( pi, 2*pi, 3 )))
close all; plot(sin(linspace( pi, 2*pi, 3 )))
close all; plot(sin(linspace( pi, 2*pi, 30 )))
close all; plot(sin(linspace( pi, 2*pi, 300 )))
close all; plot(sin(linspace( pi, 3*pi, 300 )))
reshape( 1:24, 2, 3, 4)
ans(:,:,1) =
1 3 5
2 4 6
ans(:,:,2) =
7 9 11
8 10 12
ans(:,:,3) =
13 15 17
14 16 18
ans(:,:,4) =
19 21 23
20 22 24
diary off