The purpose of this function is to query at once the cell array N of all vertex neighbor indices... of every vertices, nothing less (!)
Output N must be a cell array since of course each vertex may have a different number of neighbors.
For example, for an input filled octahedron whom triangulation is
T = [1, 2, 3;...
1, 3, 4;...
1, 4, 5;...
1, 2, 5;...
2, 3, 6;...
3, 4, 6;...
4, 5, 6;...
2, 5, 6;...
2, 3, 4;...
2, 4, 5;...
1, 2, 4;...
2, 4, 6],
then the output N is a 6x1 cell array of integers row vectors, such that :
N(1,1) = {[2, 3, 4, 5]};
N(2,1) = {[1, 3, 4, 5, 6]};
N(3,1) = {[1, 2, 4, 6]};
N(4,1) = {[1, 2, 3, 5, 6]};
N(5,1) = {[1, 2, 4, 6]};
N(6,1) = {[2, 3, 4, 5]};
Indeed vertex #2 is part of triangles [1, 2, 3], [1, 2, 5], [2, 3, 6], [2, 5, 6], [2, 3, 4], [2, 4, 5], [1, 2, 4], and [2, 4, 6], it then admit all the other vertices as neighbors ([1, 3, 4, 5, 6]).
Hypothesis / conditions :
- a vertex is the neighbor of another if they are linked with an edge in at least one same triangle. A vertex is not neighbor of itself.
- Output N row order is crucial since row number actually corresponds to the vertex id / index.
- Output N cells content order doesn't matter, but it doesn't admit any duplicated index / value.
Tip : solving my previous problems, and especially query_vertex_neighbors will help you to fully understand and solve this one.
NB : the question of unreferenced vertices is not tacled here. We just supposed there are not.
See also
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers27
Suggested Problems
-
7231 Solvers
-
1059 Solvers
-
Convert Roman to Arabic Numerals
120 Solvers
-
259 Solvers
-
896 Solvers
More from this Author42
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Pedagogic solution is available in position 2 (commented, same as solution 1 but more explicit thus suboptimal).
In problem 45261, my solution produces a cell array with the correct contents except that my vectors are columns not rows as required in the solution tests. How do I change the contents of each cell from a column to row vector?
Hi Lloyd, I am sorry I discover your comment only now. Maybe use rowfiun instead of cellfun. Else, just transpose your column vector inside its cell.
@Lloyd cellfun(@transpose, ca, UniformOutput = false) when ca is your cell array, but as you've already found the best choice is often to construct ca such that this step is not even necessary.