How to work around memory errors?

2 ビュー (過去 30 日間)
Michael J
Michael J 2015 年 3 月 4 日
編集済み: Stephen23 2015 年 3 月 6 日
Hi,
I am trying to create an object represented by a matrix of coordinate points. This object will be a subset of a larger surface, say blue. What I have is two matrices of coordinate points for two surfaces, blue and red, one inside the other (red is inside blue), and I am trying to create a third surface that is points of blue within a radius of points of the boundary points of red. The code I have so far is:
idx = true(1,size(blue,2));
for pointb=blue
pb = repmat(pointb,1,length(boundred));
idx = idx & sum((pb-boundred).^2)<r^2;
end
A = blue(idx);
where A is the matrix of coordinate points from blue.
This gives me the error:
Error using repmat
Out of memory. Type HELP MEMORY for your options.
which I don't know how to get around. My matrices are very large matrices, one ~6000x3 and the other ~850,000x3. Is there a way to smooth the matrices without losing too much information? Or another method to deal with large data and memory restrictions? Thanks in advance for any help!

採用された回答

James Tursa
James Tursa 2015 年 3 月 4 日
I guess the obvious suggestion is don't use repmat, but rewrite the sum((pb-boundred).^2) calculation as a loop instead. What are the dimensions of blue and boundred?
  4 件のコメント
Michael J
Michael J 2015 年 3 月 6 日
Thank you for explaining how my code can be improved on and helping me with a solution! It worked in about 3 minutes! Much faster than the several hours my original code was taking.
Stephen23
Stephen23 2015 年 3 月 6 日
編集済み: Stephen23 2015 年 3 月 6 日
@Michael J: the improvements that James Tursa made are well documented, you should read and learn these for your future code:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by