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 Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 9월 28일

댓글:

2018년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by