Is it possible to make combvec function faster

Hi All, After running my code with matlab profiler I see that combvec function is taking the most time. Is it possible to use any other function which is faster than combvec or is there are any other functions which is more useful parallel processing?
thanks in advance

2 件のコメント

Jan
Jan 2018 年 9 月 28 日
Please post the relevant part of the code and which inputs you use. It matters if you call combvec millions of times for small inputs or once for a huge input, of if you operator on many small vectors or a few big matrices.
Stephen23
Stephen23 2018 年 9 月 28 日
編集済み: Stephen23 2018 年 9 月 28 日
Raihan Ul Islam's "Answer" moved here and formatted correctly:
Here transformedRefVal size can be 310*5*5 and attrWeight size can be 5
for i=1:size(transformedRefVal,3)
transformedRefVal(:,:,i)=power(transformedRefVal(:,:,i),attrWeight(i));
if i==1
xb3=combvec(transformedRefVal(:,:,i));
else
xb3=combvec(xb3,transformedRefVal(:,:,i));
end
end

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

 採用された回答

Jan
Jan 2018 年 9 月 29 日

1 投票

You can inline the code of combvec:
X = rand(310, 5, 5);
Y = rand(1, 5);
sX = size(X, 2);
for i = 1:size(X, 3)
X(:,:,i) = power(X(:,:,i), Y(i));
if i == 1
xb3 = X(:,:,i); % combvec(X) is the same as X
else
s1 = size(xb3, 2);
xb3 = [repmat(xb3, 1, sX); repelem(X(:,:,i), 1, s1)];
end
end
This take 3.8 seconds on my R2016b, instead of 4.8 seconds of the original version.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by