Is it possible to make combvec function faster

6 views (last 30 days)
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 Comments
Jan
Jan on 28 Sep 2018
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 on 28 Sep 2018
Edited: Stephen23 on 28 Sep 2018
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

Sign in to comment.

Accepted Answer

Jan
Jan on 29 Sep 2018
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.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!