フィルターのクリア

How to remove the for loop from the following code?

5 ビュー (過去 30 日間)
H R
H R 2021 年 11 月 9 日
回答済み: Voss 2021 年 12 月 29 日
'Index' is an array of length N. Every elemnt of the array Index is an integer (from 1 to 7)
"xxtr" is a sample matrix with size NxM. This means for every sample (row) of matrix 'xxtr' there is an equivalent integer value in array 'Index'
Ecah element of the cell 'myRF{c,i}' is a fitted fitrensemble model that can predict output y for any sample x.
Is there a way that I can vectorize the following code by excluding the nested for loops (for efficincy purpose)?
Thanks.
for i=1:4
for jj=1:size(xxtr,1)
c=Index(jj);
x=xxtr(jj,:);
[y]=predict(myRF{c,i},x) ; % predictions
yy(jj,i)=y; %
end
end

採用された回答

Voss
Voss 2021 年 12 月 29 日
yy = cellfun(@(x,y)predict(x,y),myRF(Index,:),repmat(num2cell(xxtr,2),1,4));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by