Reorganize vector elements without losing neighbor dependencies?
Show older comments
I have the following problem: I have a square mesh of which I know all points and all their neighbor points. Saved as y, z, P, PNorth, PEast, PSouth, PWest. Here is an example with just a few points:

Now I put a shape in this mesh but not all of the points are in this shape. So I want to delete the entries that are not inside the shape, but without losing the neighbor point dependencies.
I was thinking of some kind of substitution with numbers, is that possible?
%the neighbor point in the north of point number 4 is number 5
P = [0, 0, 0, 4, 5, 0, 7, 0];
PNorth = [0, 0, 0, 5, 0, 0, 0, 0];
%now i would like to delete the zero entries, without losing these
%dependencies. Point number 4 should have index 1 etc...
old = [4,5,7];
new = [1,2,3];
subs(P,old,new); % (this does not worked, but it's like what it should do)
subs(PNorth,old,new);
%and that's the result
P = [1, 2, 3];
PNorth = [2, 0, 0];
Any idea how that could work? It should work fast for larger amounts of points, so i can save memory.
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!