MATLAB学习(2)——zeros

语法:

1 X = zeros               %  返回标量0
2 X = zeros(n)            %  返回零的n×n矩阵
3 X = zeros(sz1,...,szN)  %  返回sz1-by -...- by-szN零数组,其中sz1,...,szN表示每个维度的大小。例如,zeros(2,3)返回一个2×3的矩阵。
4 X = zeros(sz)           %  返回一个零数组,其中大小矢量sz定义大小(X)。例如,zeros([2 3])返回一个2×3的矩阵。
5 X = zeros(___,typename) %  返回数据类型为typename的零数组。例如,zeros('int8')会返回一个标量,即8位整数0.您可以使用前面语法中的任何输入参数。
6 X = zeros(___,'like',p) %  返回像p这样的零数组;也就是说,与p相同的数据类型(类),稀疏性和复杂性(真实或复杂)。你可以指定typename或'like',但不能同时指定。

Examples

X = zeros(4)   %Create a 4-by-4 matrix of zeros.
X =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0

 

X = zeros(2,3,4);  %Create a 2-by-3-by-4 array of zeros.
size(X)
ans =
     2     3     4

A = [1 4; 2 5; 3 6];   %Create an array of zeros that is the same size as an existing array.
sz = size(A);
X = zeros(sz)

%X = zeros(size(A));
X =
     0     0
     0     0
     0     0

 

X = zeros(1,3,'uint32')  %Create a 1-by-3 vector of zeros whose elements are 32-bit unsigned integers.
X =
  1×3 uint32 row vector

   0   0   0
class(X)
ans =
uint32
%Create a scalar 0 that is complex like an existing array instead of real valued.
p = [1+2i 3i]; %First, create a complex vector.
X = zeros('like',p)    Create a scalar 0 that is complex like p.
X =
   0.0000 + 0.0000i
p = sparse(10,10,pi);  %Create a 10-by-10 sparse matrix.

 

X = zeros(2,3,'like',p)  %Create a 2-by-3 matrix of zeros that is sparse like p.
X =
   All zero sparse: 2×3

 

posted @ 2018-06-26 09:53  Jasmineee  阅读(9930)  评论(0编辑  收藏  举报