Out of memory error for loop code

Hi everyone, I have a very simple code in which I want to find the correlation distances from one point to all the other points in the matrix. I am using bsxfun to find those distances and I am using imread as the function to read an image (The image will give me the points of the matrix).
Since the image is very big, matlab cannot make all the distances because I do not have enough memory in my computer. I tried using a supercomputer which is located in my univesity, the problem is that the supercomputer has only 96gb and I need more than that. I want to read the image by parts, but since I am trying to read the distances, it will change. For example
I have a matrix A:
1 0 0 0 1
0 0 1 0 0
1 0 0 0 1
0 0 0 0 1
1 0 0 0 1
For this matrix, the distances in the x axis of the first point with respect to the others will be:
[0 4 2 0 4 4 0 4]
And the distances in the y axis will be:
[0 0 1 2 2 3 4 4]
Lets say that I cut this matrix in two parts, and I would have 2 matrices like this:
1 0 0 0 1
0 0 1 0 0
1 0 0 0 1
and
0 0 0 0 1
1 0 0 0 1
If I try to make the y-axis distances for the first matrix, they will be:
[0 0 1 2 2]
but for the next matrix will be:
[0 1 1], instead of what I had before [3 4 4]
Does anyone know how can I solve this issue? Thank you.

5 个评论

How did you arrive at these 8 numbers [0 4 2 0 4 4 0 4] as the distances from the upper left pixel to the other 24 pixels in this 5 by 5 image?
And, let's take a step back and ask WHY do think think you want this information. What will it do for you if you had it? Let's pretend you had infinite memory and were able to get the "correlation distance" or "distance" (whichever) - what would that do for you? What would you do with that information? And what is correlation distance exactly? Do you have a formula for it? I presume it's not just the Euclidean/Pythagorean distance = sqrt(deltaX^2+deltaY^2) but what is it?
The distances are from the first point trough all the other points(just the ones), for example in the first point, the distances will be 0 (itself) 4 (last element of the first row), 2(third one in the matrix, since the distance is just the x-axis distance) and it goes on... I will attach you the code and image that I am using, those distances are just one step of the code and they are needed to find the statistical dependence between one point to other points
I could not attach the image, but I used the command imread, and I attached a matrix.
Why do you need it all in memory at once? Why can't you just concentrate on one pair at a time in a nested for loop?
For those of us not allowed to download stuff willy nilly from the net, can you define what "very big" means?

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

提问:

2014-2-17

评论:

2014-2-17

Community Treasure Hunt

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

Start Hunting!

Translated by