How can I fix array indices error for point cloud data?

2 views (last 30 days)
I have a datastore containing point cloud scans from an intel realsense depth camera. when I try to read the label counts:
dsTrain = PtCloudClassificationDatastore('train');
dsVal = PtCloudClassificationDatastore('test');
dsLabelCounts = transform(dsTrain,@(data){data{2} data{1}.Count});
labelCounts = readall(dsLabelCounts);
if gives me this error message:
Error using matlab.io.datastore.FileDatastore/read (line 29)
Error using ReadFcn @extractTrainingData for file:
/Users/aj/Library/Application Support/MathWorks/MATLAB
Add-Ons/Collections/Classify point clouds using PointNet(点群深層学習による点群の分
類)/files/train/Microwave/Microwave_83.ply
Array indices must be positive integers or logical values.
Error in PtCloudClassificationDatastore>extractTrainingData (line 98)
name=fname(idx(end-1)+1:idx(end)-1);
Error in PtCloudClassificationDatastore/read (line 55)
[data(idx,:),info(idx)] = read(this.FileDatastore);
Error in matlab.io.datastore.TransformedDatastore/read (line 219)
[data, info] = read(ds.UnderlyingDatastores{1});
Error in matlab.io.Datastore/readall (line 263)
data = read(copyds);
Error in matlab.io.datastore.TransformedDatastore/readall (line 281)
data = readall@matlab.io.Datastore(copyds, varargin{:});

Answers (1)

Omega
Omega on 27 Dec 2023
Hi FN,
I understand that you are facing "Array indices must be positive integers or logical values" error. The error message indicates that there's an issue with array indexing inside the custom read function ("extractTrainingData") used by the "PtCloudClassificationDatastore". Specifically, the error occurs when the function tries to access parts of the filename using array indices, and it encounters an index that is not a positive integer or logical value.
The error message points to this line:
name=fname(idx(end-1)+1:idx(end)-1);
This line is attempting to extract a substring from "fname" using indices stored in "idx". If "idx" contains non-positive or non-integer values, MATLAB will throw an error.
Here are some steps you can take to troubleshoot and fix this error:
  1. Check the "idx" Array: Ensure that the "idx" array contains only positive integers. You may want to add a check or assert statement before this line to confirm that "idx" is as expected.
  2. Validate File Names: Make sure that all file names in your dataset follow a consistent naming convention that matches what the "extractTrainingData" function expects.
  3. Check for Off-by-One Errors: MATLAB uses 1-based indexing, which can sometimes lead to off-by-one errors when porting code from 0-based indexing languages. Make sure the indices used in the slicing operation are correctly computed.
  4. Check for Empty Arrays: If "idx" can potentially be empty, you need to add a check before attempting to use it for indexing. Attempting to index with an empty array will cause an error.
  5. Debug the Function: Use MATLAB's debugging tools to set a breakpoint at the line of the error and inspect the values of "fname" and "idx" at runtime. This can help you identify what's going wrong.
  6. Handle Edge Cases: If the error is caused by edge cases (like file names that don't contain the expected delimiters), modify the "extractTrainingData" function to handle these cases gracefully.
Hope it helps!

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!