Is it possible to make combvec function faster
6 views (last 30 days)
Show older comments
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
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
on 28 Sep 2018
Edited: Stephen23
on 28 Sep 2018
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
Accepted Answer
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)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!