Concatenate large matrices a bottleneck in function

1 visualización (últimos 30 días)
David McVea
David McVea el 4 de Nov. de 2020
Comentada: Walter Roberson el 4 de Nov. de 2020
Hi,
I have a function that concatenates two matrices, size of 100000 X 90 for an outcome of 100000 X 180.
This is a significant bottleneck as the function has to repeat many times.
Pre-allocating the outcome does not seem to make any difference, and using cat() or [] also seems to make no difference.
Does anyone have suggestions on how to speed this up?
Thank you.
  2 comentarios
Sylvain
Sylvain el 4 de Nov. de 2020
can you post your code?
are you trying to do this ?
A=ones(100000,90);
B=2*ones(100000,90);
C = [A,B];
David McVea
David McVea el 4 de Nov. de 2020
Hello -
Thanks for your comment.
I won't post my code because, yes, that is exactly what I am doing.

Iniciar sesión para comentar.

Respuestas (1)

Subhadeep Koley
Subhadeep Koley el 4 de Nov. de 2020
The horzcat() function is usually faster than cat() or [, ]. You may use it.
A = ones(100000,90);
B = 2*ones(100000,90);
result = horzcat(A, B);
  1 comentario
Walter Roberson
Walter Roberson el 4 de Nov. de 2020
The timing tests I tried show horzcat(A,B) and [A,B] and cat(2,A,B) to be indistinguishable in timing -- the differences were below random variation

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by