您的位置:首页 > 编程语言 > MATLAB

Matlab中ones()用法

2013-04-08 17:33 246 查看
 ONES   Ones array.

    ONES(N) is an N-by-N matrix of ones.

 

    ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones.

 

    ONES(M,N,P,...) or ONES([M N P ...]) is an M-by-N-by-P-by-... array of

    ones.

 

    ONES(SIZE(A)) is the same size as A and all ones.

 

    ONES with no arguments is the scalar 1.

 

    ONES(M,N,...,CLASSNAME) or ONES([M,N,...],CLASSNAME) is an M-by-N-by-...

    array of ones of class CLASSNAME.

由此可以看出,ones的作用是产生全1矩阵,ones(N)是产生一个N*N的全1矩阵,如:

>> ones(3)

ans =

     1     1     1

     1     1     1

     1     1     1

ones(M,N)产生一个M*N的矩阵,如

>> ones(3,4)

ans =

     1     1     1     1

     1     1     1     1

     1     1     1     1

需要注意的是ones(size(A))的用法,size(A)返回的是A的大小参数,如果A是一个3X4的矩阵的话,则返回的参数应该是3  4,所以ones(size(A))产生的矩阵应该是与A大小相同的全1矩阵
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Matlab ones