I have written a code as mentioned below, its a for loop in which i want to store the array of each polygon, but im only able to save the last polygon values.
function [x, y, dt] = simple_polygon(numSides,numpoly)
if numSides < 3
x = [];
y = [];
dt = DelaunayTri();
return
end
oldState = warning('off', 'MATLAB:TriRep:PtsNotInTriWarnId');
valueOfX = zeros(100,100);
valueOfY = zeros(100,100);
figure
for i = 1 : numpoly
fudge = ceil(numSides/10);
x = rand(numSides+fudge, 1);
y = rand(numSides+fudge, 1);
dt = DelaunayTri(x, y);
boundaryEdges = freeBoundary(dt);
numEdges = size(boundaryEdges, 1);
while numEdges ~= numSides
if numEdges > numSides
triIndex = vertexAttachments(dt, boundaryEdges(:,1));
triIndex = triIndex(randperm(numel(triIndex)));
keep = (cellfun('size', triIndex, 2) ~= 1);
end
if (numEdges < numSides) || all(keep)
triIndex = edgeAttachments(dt, boundaryEdges);
triIndex = triIndex(randperm(numel(triIndex)));
triPoints = dt([triIndex{:}], :);
keep = all(ismember(triPoints, boundaryEdges(:,1)), 2);
end
if all(keep)
warning('Couldn''t achieve desired number of sides!');
break
end
triPoints = dt.Triangulation;
triPoints(triIndex{find(~keep, 1)}, :) = [];
dt = TriRep(triPoints, x, y);
boundaryEdges = freeBoundary(dt);
numEdges = size(boundaryEdges, 1);
end
boundaryEdges = [boundaryEdges(:,1); boundaryEdges(1,1)];
x = dt.X(boundaryEdges, 1);
y = dt.X(boundaryEdges, 2);
valueOfX(i) = x;
valueOfY(i)= y;
warning(oldState);
hold all
patch(x,y,'r-')
end
end
In the code, in "valueofX and valueofY", i tried to store the array, but its showing error. Please help me to store the array for each polygon.

 채택된 답변

Stalin Samuel
Stalin Samuel 2015년 11월 23일
편집: Stalin Samuel 2015년 11월 23일

0 개 추천

  • in your function you return the values of x,y
  • function [x, y, dt] = simple_polygon(numSides,numpoly)
  • the array values are stored in valueOfX,valueOfY
  • So you need to change your function like-----> function [valueOfX, valueOfY, dt] = simple_polygon(numSides,numpoly)

댓글 수: 7

SUSHMA MB
SUSHMA MB 2015년 11월 23일
Thank you for replying, but im still getting the error.
Stalin Samuel
Stalin Samuel 2015년 11월 23일
post the error message
SUSHMA MB
SUSHMA MB 2015년 11월 23일
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in simple_polygonNEW (line 44) valueOfA(i) = x;
Try
valueOfX(i,:) = x;
valueOfY(i,:)= y;
SUSHMA MB
SUSHMA MB 2015년 11월 23일
Subscripted assignment dimension mismatch.
Error in simple_polygonNEW (line 44) valueOfA(i,:) = x;
SUSHMA MB
SUSHMA MB 2015년 11월 24일
Thank you for your help....

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Computational Geometry에 대해 자세히 알아보기

태그

질문:

2015년 11월 23일

댓글:

2015년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by