我在运行官方文档的代码,结果它报了错

16 次查看(过去 30 天)
Qiyuan
Qiyuan 2026-1-24,12:26
回答: Samhitha 2026-1-29,11:26
你好
起初是我在尝试用matlab进行点云数据拼接,结果它报了错:
代码是:
19 %进行点云数据的预处理:
20 %导入含有噪声的点云数据
21 noisy_pc=pointCloud('Image_Cloud_20260121_17_13_14_668.ply');
22 pcshow(noisy_pc)
23 %pcd_downsampled = pcdownsample(noisy_pc, 'random', 0.1);
24 % 应用高斯滤波进行去噪
25 filtered_pc=pcdenoise(noisy_pc);
运行信息是:
2026-01-24 20:16:37.444s | S : POINTCLOUD > IMPORT
+0.022s | I : POINTCLOUD > IMPORT : Point cloud label = 'Image_Cloud_20260121_17_13_14_668.ply'
2026-01-24 20:16:37.579s | S : POINTCLOUD > IMPORT > READ DATA
+8.888s | E : POINTCLOUD > IMPORT > READ DATA
+9.024s | E : POINTCLOUD > IMPORT
2026-01-24 20:16:46.585s | S : POINTCLOUD > INFO
+0.006s | I : POINTCLOUD > INFO : Point cloud label = 'Image_Cloud_20260121_17_13_14_668.ply'
| V : 2290000 = number of points
| V : 2290000 = number of activated points
| V : 0 = number of deactivated points
| V : -27.787 = min / x
| V : 21.221 = max / x
| V : -54.912 = min / y
| V : 0.000 = max / y
| V : -35.586 = min / z
| V : 38.366 = max / z
+0.077s | E : POINTCLOUD > INFO
报错信息是:
未识别类 'pointCloud' 的方法、属性或字段 'Location'。
出错 pointclouds.internal.pcui.validateAndParseInputsXYZC (第 14 行)
xyzPoints = ptCloud.Location;
出错 pcshow>validateAndParseInputs (第 71 行)
[X, Y, Z, C, map, ptCloud] = pointclouds.internal.pcui.validateAndParseInputsXYZC(mfilename, varargin{1});
出错 pcshow (第 5 行)
[X, Y, Z, C, map, ptCloud, params] = validateAndParseInputs(varargin{:});
出错 Left_Group_2 (第 22 行)
pcshow(noisy_pc)
然后我就尝试去用最简单的代码去排除错误,我直接进入了这篇官方文档,尝试去运行示例文件,结果它竟然也报了错:
Read Point Cloud from a PLY File
代码是:
ptCloud = pcread('teapot.ply');
pcshow(ptCloud);
运行信息是:
2026-01-24 17:27:59.529s | S : POINTCLOUD > IMPORT
+0.051s | I : POINTCLOUD > IMPORT : Point cloud label = 'noLabel'
2026-01-24 17:27:59.608s | S : POINTCLOUD > IMPORT > READ DATA
+0.017s | E : POINTCLOUD > IMPORT > READ DATA
+0.098s | E : POINTCLOUD > IMPORT
2026-01-24 17:27:59.631s | S : POINTCLOUD > INFO
+0.001s | I : POINTCLOUD > INFO : Point cloud label = 'noLabel'
| V : 41472 = number of points
| V : 41472 = number of activated points
| V : 0 = number of deactivated points
| V : -3.000 = min / x
| V : 3.434 = max / x
| V : -2.000 = min / y
| V : 2.000 = max / y
| V : 0.000 = min / z
| V : 3.150 = max / z
+0.010s | E : POINTCLOUD > INFO
错误信息是:
未识别类 'pointCloud' 的方法、属性或字段 'Location'。
rowColContextMenu = rowColContextMenu && (~isempty(ptCloud) && ~ismatrix(ptCloud.Location));
pointclouds.internal.pcui.updateColorContextMenu(hFigure);
initContextMenu(hFigure, hui);
registerCallbacks(hFigure,scatterObj,vertAxis,vertAxisDir,ptCloudThreshold);
pointclouds.internal.pcui.initializePCSceneControl(hFigure, currentAxes,...
  1 个评论
Esther
Esther 2026-1-28,8:39
请在MATLAB命令行窗口输入:
>> which -all pointCloud
看下返回的结果中是否包含和MATLAB内置函数同名的其他函数呢?如有,请将其他函数重新命名,以避免和MATLAB内置函数冲突。

请先登录,再进行评论。

回答(1 个)

Samhitha
Samhitha 2026-1-29,11:26
This issue is caused by a name conflict with the MATLAB built‑in "pointCloud" class. When another third‑party or custom class named "pointCloud" exists on the MATLAB path, MATLAB may call that version instead of the built‑in one. Some third‑party "pointCloud" classes do not contain the "Location" property, which causes "pcshow" to fail when it tries to access "ptCloud.Location".
To fix this, run the following command in the MATLAB Command Window:
which -all pointCloud
check whether multiple definitions are returned. If a non‑MathWorks version appears, remove that folder from the MATLAB path or rename the conflicting class.
Afterward, restore the path and refresh the cache using:
restoredefaultpath
rehash toolboxcache
clear classes
After fixing the path, confirm correct behavior with:
ptCloud = pcread('teapot.ply');
pcshow(ptCloud);
If "pcshow" runs without error and "ptCloud.Location" is accessible, MATLAB is using the correct built‑in "pointCloud" class.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Point Cloud Processing 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!