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 comentarios

Jan
Jan el 28 de Sept. de 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 el 28 de Sept. de 2018
Editada: Stephen23 el 28 de Sept. de 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

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 29 de Sept. de 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.

Más respuestas (0)

Categorías

Productos

Versión

R2018a

Preguntada:

el 28 de Sept. de 2018

Comentada:

el 2 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by