How do I tackle MATLAB running out of memory?

135 次查看(过去 30 天)
In continuation to the analysis of my UAV-LiDAR data based on the extraction of forest tree metrics script that I am tweaking, I am running into some memory trouble. I have been reading a lot of documentation but I cannot seem to wrap my head around this.
% Segment individual trees
label2D = helperSegmentTrees(canopyModel,treeTopRowId,treeTopColId,minTreeHeight);
% Identify row and column id of each point in label2D and transfer labels
% to each point
rowId = ceil((ptCloud.Location(:,2) - ptCloud.YLimits(1))/gridRes) + 1;
colId = ceil((ptCloud.Location(:,1) - ptCloud.XLimits(1))/gridRes) + 1;
ind = sub2ind(size(label2D),rowId,colId);
label3D = label2D(ind);
% Extract valid labels and corresponding points
validSegIds = label3D ~= 0;
ptVeg = select(ptCloud,validSegIds);
while running the ptVeg = select(ptCloud, validSegIds); this is where MATLAB runs out of memory, and displays the following error:
Out of memory.
Error in pointclouds.internal.pc.getSubset
[loc, c, nv, intensity, r] = pointclouds.internal.pc.getSubset( ...
[loc, c, nv, intensity, r] = this.subsetImpl(indices, outputSize);
veglabel3D = label3D(validSegIds);
% Assign color to each label
numColors = max(veglabel3D);
colorMap = randi([0 255],numColors,3)/255;
labelColors = label2rgb(veglabel3D,colorMap,OutputFormat="triplets");
% Visualize tree segments
figure
pcshow(ptVeg.Location,labelColors)
title("Individual Tree Segments")
view(2)
uicontrol('Visible', 'off')
It also shows a similar error while running the subsequent part of the script -
% Extract tree attributes
treeMetrics = helperExtractTreeMetrics(normalizedPoints,label3D);
Out of memory.
filteredPoints = normalizedPoints(validLabels,:);
% Display first 5 tree segments metrics
disp(head(treeMetrics));
My LiDAR dataset is around 25 gigabytes (colourised point cloud of 35 hectares of a forest stand).
I am using an Image Processing Computer with 256 gigabytes of RAM, a massive hard drive and an NVIDIA GeForce RTX 3090.
Could somebody please point me in the right direction? Super grateful for Mathworks community's help! :)
Attached below is a screenshot for additional information:

回答(1 个)

Harshit Gupta
Harshit Gupta 2022-10-3
As per my understanding, you want to find ways to avoid getting the error "Out of memory" while working with MATLAB.
When your code operates on large amounts of data or does not use memory efficiently, MATLAB might produce an error in response to a very large array size, or it might run out of memory.
Please refer to Memory Usage information from the following documentation URL:
Specifically, to the sections:
  1. Strategies for Efficient Use of Memory
  2. Resolving "Out of Memory" Errors
Concepts:
  1. Memory Allocation
  2. Memory Management Functions
You can also refer to the following link for resolving "Out of Memory" errors:

类别

Help CenterFile Exchange 中查找有关 Licensing on Cloud Platforms 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by