Array of ClassificationTree objects

3 ビュー (過去 30 日間)
Rashid
Rashid 2012 年 6 月 6 日
I am very new to MATLAB. I was trying to train some ClassificationTree's and the assign them in array with the following snippet
for k = 1:rows
tree=ClassificationTree.fit(data(1:k, 1:cols),labels(1:k));
ensemble(k)=tree;
end
however when I run this I get following error
??? Error using ==> DisallowVectorOps>DisallowVectorOps.subsasgn at 28
You cannot assign to an object of class double using () indexing.
Error in ==> dwm02 at 7
ensemble(k)=tree;
is there any way of doing this? MATLAB help on object arrays is a bit confusing..
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 6 日
How did you initialize "ensemble" ?

サインインしてコメントする。

採用された回答

Ilya
Ilya 2012 年 6 月 6 日
Use a cell array. Pre-allocate the array by
ensemble = cell(rows,1);
And then assign using curly brackets:
ensemble{k} = tree;
  2 件のコメント
Rashid
Rashid 2012 年 6 月 7 日
Thanks, this works very well!
Just a question - is it absolutely necessary to pre-allocate the array? My array will have dynamic nature, so I would prefer dynamic allocation of memory as well.
Walter Roberson
Walter Roberson 2012 年 6 月 7 日
It is not absolutely necessary to pre-allocate: it is a matter of efficiency.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClassification Ensembles についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by