Default dimension of one-dimensional array of objects
3 ビュー (過去 30 日間)
古いコメントを表示
Is there a way to specify default dimensions of an object array when only one dimension is used on instantiation. For example, initialising array of objects like below will return an array of dimensions (1, 5)
objArray(5) = MyClass;
I would like the default behaviour to be equivalent to the one below, where the array is of dimensions (5, 1).
objArray(5, 1) = MyClass;
I would require this to be able to extract certain properties of the class in correct arrangement after concatenation, e.g.
[objArray.propertyOne]
0 件のコメント
採用された回答
Matt J
2021 年 7 月 12 日
編集済み: Matt J
2021 年 7 月 12 日
The result of [objArray.propertyOne] will always be a row vector independent of the shape of objArray, so I don't think having the output object array in column vector form will help you (but you can use vertcat(objArray.propertyOne) instead ).
To answer your question, though, you can ensure a column vector shape by building and shaping the array inside the constructor, e.g., with
function objArray=MyClass(varargin)
% objArray=MyClass(dim1,dim2,dim3,...)
if nargin==0, return;end
objArray(varargin{:})=MyClass;
if nargin==1
objArray=objArray(:);
end
or whatever the condition should be.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!