Why won't this function assign the correct name to its output?

Hi! i've run into a bit of trouble when trying to plot some aircraft components with delaunayTriangulation. from the file i've read/imported, ive created tables of the coordinates of each point of the different components. this was fine until i encountered some difficult to work with values, i believe the dimensions and coordinates are so that DT cannot create a triangulation matrix because the points are too few and too similar.
I am (admittedly quite terribly) trying to work around this by changing some of the values of these coordinates very slightly so that they can be properly plotted.
my only problem is, when i pass the necessary table into a function i have created, the values change correctly but the output is assigned incorrecly so it cannot be used later on. Hope this gives enough context
i have used a relatively large value for the adjustment to easily see what the code is doing, this will be dramatically reduced once it's working correctly.
%fin_2 is a table with values
format long g
% 'x' 'y' 'z'
fin_2 = array2table( ...
[7.56636000000000 0.615000000000000 -0.141010000000000
9.13145000000000 0.615000000000000 -0.141010000000000
7.64832400000000 0.615000000000000 -0.238691000000000
9.17700400000000 0.615000000000000 -0.238691000000000
7.82950300000000 0.615000000000000 -0.454611000000000
7.82950300000000 0.615000000000000 -0.454611000000000], 'VariableNames', {'x', 'y', 'z'})
fin_2 = 6×3 table
x y z ________ _____ _________ 7.56636 0.615 -0.14101 9.13145 0.615 -0.14101 7.648324 0.615 -0.238691 9.177004 0.615 -0.238691 7.829503 0.615 -0.454611 7.829503 0.615 -0.454611
adjustIfNotPlottable(fin_2)
Unrecognized function or variable 'adjustIfNotPlottable'.
plotPoints(fin_2)
function adjustIfNotPossible(geometry)
[r,c] = size(geometry);
for colNum = 1:c
for rowNum = 1:r-1
if geometry{rowNum+1,colNum} == geometry{rowNum,colNum}
geometry{rowNum,colNum} = (geometry{rowNum,colNum} + rowNum*0.1)
end
end
end
end
function plotPoints(pointsToPlot)
scatter3(pointsToPlot.x,pointsToPlot.y,pointsToPlot.z,"MarkerEdgeColor","none")
DT = delaunayTriangulation([pointsToPlot.x,pointsToPlot.y,pointsToPlot.z]);
K = convexHull(DT);
hold on
axis equal
trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),'EdgeColor','k','FaceColor','g')
end
When run, the output of the first function remains as geometry, although the values are correct. The actual values of fin_2 do not seem to get updated, meaning that it still cannot be triangulated. I'm just looking for a way to make the function know that the output should be called either the same as the input or make it possible for the output of 'geometry' can then be assigned to a table called fin_2_adjusted or something along those lines.
Thanks a bunch!!
my apologies if this question is asked badly

 Accepted Answer

%fin_2 is a table with values
format long g
% 'x' 'y' 'z'
fin_2 = array2table( ...
[7.56636000000000 0.615000000000000 -0.141010000000000
9.13145000000000 0.615000000000000 -0.141010000000000
7.64832400000000 0.615000000000000 -0.238691000000000
9.17700400000000 0.615000000000000 -0.238691000000000
7.82950300000000 0.615000000000000 -0.454611000000000
7.82950300000000 0.615000000000000 -0.454611000000000], 'VariableNames', {'x', 'y', 'z'})
fin_2 = 6×3 table
x y z ________ _____ _________ 7.56636 0.615 -0.14101 9.13145 0.615 -0.14101 7.648324 0.615 -0.238691 9.177004 0.615 -0.238691 7.829503 0.615 -0.454611 7.829503 0.615 -0.454611
fin_2 = adjustIfNotPossible(fin_2)
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.615 -0.14101 9.13145 0.615 -0.14101 7.648324 0.615 -0.238691 9.177004 0.615 -0.238691 8.329503 0.615 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.715 -0.14101 9.13145 0.615 -0.14101 7.648324 0.615 -0.238691 9.177004 0.615 -0.238691 8.329503 0.615 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.715 -0.14101 9.13145 0.815 -0.14101 7.648324 0.615 -0.238691 9.177004 0.615 -0.238691 8.329503 0.615 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.715 -0.14101 9.13145 0.815 -0.14101 7.648324 0.915 -0.238691 9.177004 0.615 -0.238691 8.329503 0.615 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.715 -0.14101 9.13145 0.815 -0.14101 7.648324 0.915 -0.238691 9.177004 1.015 -0.238691 8.329503 0.615 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.715 -0.14101 9.13145 0.815 -0.14101 7.648324 0.915 -0.238691 9.177004 1.015 -0.238691 8.329503 1.115 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ _________ 7.56636 0.715 -0.04101 9.13145 0.815 -0.14101 7.648324 0.915 -0.238691 9.177004 1.015 -0.238691 8.329503 1.115 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ __________________ 7.56636 0.715 -0.04101 9.13145 0.815 -0.14101 7.648324 0.915 0.0613090000000001 9.177004 1.015 -0.238691 8.329503 1.115 -0.454611 7.829503 0.615 -0.454611
geometry = 6×3 table
x y z ________ _____ __________________ 7.56636 0.715 -0.04101 9.13145 0.815 -0.14101 7.648324 0.915 0.0613090000000001 9.177004 1.015 -0.238691 8.329503 1.115 0.045389 7.829503 0.615 -0.454611
fin_2 = 6×3 table
x y z ________ _____ __________________ 7.56636 0.715 -0.04101 9.13145 0.815 -0.14101 7.648324 0.915 0.0613090000000001 9.177004 1.015 -0.238691 8.329503 1.115 0.045389 7.829503 0.615 -0.454611
plotPoints(fin_2)
function geometry = adjustIfNotPossible(geometry)
[r,c] = size(geometry);
for colNum = 1:c
for rowNum = 1:r-1
if geometry{rowNum+1,colNum} == geometry{rowNum,colNum}
geometry{rowNum,colNum} = (geometry{rowNum,colNum} + rowNum*0.1)
end
end
end
end
function plotPoints(pointsToPlot)
scatter3(pointsToPlot.x,pointsToPlot.y,pointsToPlot.z,"MarkerEdgeColor","none")
DT = delaunayTriangulation([pointsToPlot.x,pointsToPlot.y,pointsToPlot.z]);
K = convexHull(DT);
hold on
axis equal
trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),'EdgeColor','k','FaceColor','g')
end

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!