Concatenation in Matlab (with or without copying elements)
古いコメントを表示
Assume we have X = [A, B] where A and B are two vectors (or matrices). Is concatenation operation copies elements in A? If so is it possible to do concatenation without copying elements?
Possible answer to the second. What if I do the following in order to avoid copying elements: X(1:length(A)) = A; X(length(A)+1:length(A)+length(B)) = B; Does 'copy-on-write' work in this context?
Follow-up question: How can I benchmark these two codes with respect to memory usage? Any ideas?
採用された回答
その他の回答 (1 件)
the cyclist
2012 年 1 月 14 日
This page will provide you with a lot of information about memory management in MATLAB: http://www.mathworks.com/support/tech-notes/1100/1106.html
When you do ...
>> X = A;
MATLAB doesn't make a copy of A, until you change an element of X. (Then it copies the entire array.) However, I am pretty sure that that does not apply to concatenation. I don't think there is a way to carry out
>> X = [A,B];
without actually creating the new array in memory.
カテゴリ
ヘルプ センター および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!