Why do I receive an "Out of Memory" error when I attempt to render a surface with a large number of data points in MATLAB?

11 views (last 30 days)
I am attempting to create a surface plot of my data set contained in matrix "A" by using
surf(A)
But instead I receive the following error:
??? Out of memory. Type HELP MEMORY for your options.
The characteristics of "A" are
Name Size Bytes Class
A 9851x6916 545036128 double array

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
MATLAB overflows (i.e. produces an "Out of Memory" error) when attempting to render a surface from an array with a large number of data points for the following reason:
When creating a surface using the SURF function, MATLAB creates a copy of the data arrays. If there is not enough contiguous memory available to store these arrays, it will result in an overflow. For more information regarding MATLAB memory allocation, refer to the Memory Managament Guide technical note (tech note 1106) on The Mathworks Support web page.
If there is enough contiguous memory available, then the overflow is a result of the amount of memory required to render the surface.
To represent the this surface with a large number of data points requires (9851-1)*(6916-1) = 68 million quadrilaterals. Quadrilaterals are rendered by graphics engines as two triangles. Thus this particular surface requires 136 million triangles to be rendered. Each triangle is represented by 3 floating point numbers per vertex for the X, Y, Z coordinates. This works out to 4.9 gigabytes (GB) of data not including other information about colors, edges, and normals. This amount exceeds the memory available to MATLAB 7.1 (R14SP3) on a Windows platform.
To work around this issue, try reducing the amount of plotted data to produce a surface plot representative of the data.
Here is one way to downsample and plot the data:
[u v] = size(A);
t1 = 1:10:u;
t2 = 1:10:v;
b = A(t1,t2);
surf(b)

More Answers (0)

Tags

No tags entered yet.

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!