I have a point cloud made up of 37817 3D vertices (data here). For each vertex `i`

, I compute all neighbors within 15mm (`NeighborVert{i}`

). A sphere is fit using these neighbors through `sphereFit`

(source code). Squared distance of each of the identified neighbor to the surface of the sphere, denoted as `epsilon{i}(j)`

, is calculated to quantify residual of each neighbor to the fitted sphere. I then sum all values within `epsilon{i}`

across `j`

and store the result as `E(i)`

, which measures the overall fit of the sphere for neighbors of vertex `i`

. The above process is implemented through the MATLAB code below:

```
T = readtable("<path>\Vertices.xlsx", 'ReadVariableNames',false);
Vertices = table2array(T);
Vertfmt = pointCloud(Vertices);
radius = 15;
for i = 1:size(Vertices, 1)
[NeighborIndex{i}] = findNeighborsInRadius(Vertfmt, Vertices(i,:), radius);
NeighborVert{i} = Vertices(NeighborIndex{i},:);
[center(i, :), r(i)] = sphereFit(NeighborVert{i});
for j = 1:length(NeighborIndex{i})
epsilon{i}(j) = abs((NeighborVert{i}(j, 1) - center(i, 1))^2 + (NeighborVert{i}(j, 2) - center(i, 2))^2 + (NeighborVert{i}(j, 3) - center(i, 3))^2 - r(i)^2);
E(i) = sum(epsilon{i}(j));
end
end
```

`epsilon{i}`

should contain multiple values because the squared distance of all neighbors of vertex `i`

to the surface of the fitted sphere is stored. However, my result showed that each `epsilon{i}`

contains only 1 value. How can I save all `epsilon{i}(j)`

s within `epsilon{i}`

during each iteration?

Besides, is my code for `E(i)`

correctly sum across `j`

for all `epsilon{i}(j)`

s?