2 回答

TA貢獻1874條經驗 獲得超12個贊
以下示例供參考:
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矩陣。
添加回答
舉報