Concatenate large matrices a bottleneck in function

조회 수: 3 (최근 30일)
David McVea
David McVea 2020년 11월 4일
댓글: Walter Roberson 2020년 11월 4일
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
Sylvain
Sylvain 2020년 11월 4일
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 2020년 11월 4일
Hello -
Thanks for your comment.
I won't post my code because, yes, that is exactly what I am doing.

댓글을 달려면 로그인하십시오.

답변 (1개)

Subhadeep Koley
Subhadeep Koley 2020년 11월 4일
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
Walter Roberson
Walter Roberson 2020년 11월 4일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by