Info

This question is closed. Reopen it to edit or answer.

The best way to add 2 arrays, element by element in order to avoid the memory's problem

1 view (last 30 days)
Dear colleagues
with this sentence i add the array X with array Y as follow:
X(:,1)=[............];
Y(:,1)=[............];
Z= reshape(bsxfun(@plus,X',Y),1,[]);
but X and Y are too big, therefore Z is a big arrays that Matlab cann't save and it is the same if Z were a matrix. this message appears: "Out of memory"
What do you think that is the best way to solve this problem? I want to avoid the loops in order to have a fast code.
Thank you for your help
  1 Comment
Roger Stafford
Roger Stafford on 10 Jul 2015
In that case try using a for-loop rather than a vectorized method. It would only add the column vector Z to the memory. Be sure and allocate Z first.

Answers (0)

Community Treasure Hunt

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

Start Hunting!