How to create a 3 * 3 * 1 array using ones or zeros?
6 ビュー (過去 30 日間)
古いコメントを表示
The help of ones or zeros tell us "If any trailing dimensions greater than 2 have a size of 1, then the output, X, does not include those dimensions". But if I really need to create a 3 * 3 * 1 array (I care about the dimension), what can I do?
1 件のコメント
Stephen23
2022 年 4 月 7 日
All arrays implicitly have infinite trailing scalar dimensions, so your array already has 3rd dimension == 1.
"Arrays in MATLAB are N-dimensional, with an infinite number of trailing singleton dimensions."
回答 (1 件)
Walter Roberson
2022 年 4 月 7 日
A = zeros(3,3)
[size(A,1), size(A,2), size(A,3)]
so using size() says that A is length 1 on the third dimension.
If you needed size() of a numeric array to show 3 x 3 x 1, then you would need to provide your own size.m (and possibly ndims.m as well), but that would have a high risk of breaking something in MATLAB.
If the object does not need to be numeric, then you could create your own class that defined its own size() method to report back whatever you wanted. You could also define arithmetic operations on the class.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!