Effacer les filtres
Effacer les filtres

How do I tackle MATLAB running out of memory?

95 vues (au cours des 30 derniers jours)
Atman Dhruva
Atman Dhruva le 24 Sep 2022
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
title("Individual Tree Segments")
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
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:

Réponses (1)

Harshit Gupta
Harshit Gupta le 3 Oct 2022
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
  1. Memory Allocation
  2. Memory Management Functions
You can also refer to the following link for resolving "Out of Memory" errors:


En savoir plus sur Labeling, Segmentation, and Detection dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by