I need to have (x, y) coordinates stored in a column of a current variable

조회 수: 11 (최근 30일)
Steven D
Steven D 2022년 4월 29일
편집: Roshan Swain 2022년 5월 4일
I am trying to have the x and y coordinates (of the vertices in the shown plot), be stored in a column of a variable (edLenArc), which contains the edge lengths of the cells in the plot. I've included a screenshot of the plot as well as a relevant snippet of the code. Thanks in advance!
% plot circular arc
crDraw = @(radius,radAng,cen,tran) [radius*cos(radAng),radius*sin(radAng)]+cen+tran;
for i=1:size(cirCenTr,1)
angValTmp=linspace(cirAngRng(i,1),cirAngRng(i,2),20);
crDrTmp=zeros(20,2);
for j=1:20
crDrTmp(j,:)=crDraw(cirRad(i),angValTmp(j),cirCenTr(i,:),...
edVrUnqInf{i}(1,:));
end
x = crDrTmp(:,1);
y = crDrTmp(:,2);
plot(x,y);
% text(x,y,'.');
axis equal;
hold on;
end
% compute edge length.
edLenArc=zeros(size(cirRad,1),1);
for i=1:size(edLenArc,1)
if cirRad(i)>0
edLenArc(i)=cirRad(i)*(cirAngRng(i,2)-cirAngRng(i,1));
else
edLenArc(i)=norm(edVrUnqInf{i}(1,:)-edVrUnqInf{i}(end,:));
end
end
faEdInf=cell(max(picNum(:)),1);
for i=1:length(edFaUnqInf)
faEdInf{edFaUnqInf(i,1)}(end+1)=i;
faEdInf{edFaUnqInf(i,2)}(end+1)=i;
end
faPerInf=zeros(max(picNum(:)),1);
for i=1:size(faPerInf,1)
if any(intCell==i)==1
for j=1:length(faEdInf{i})
faPerInf(i)=faPerInf(i)+edLenArc(faEdInf{i}(j));
end
end
end
  댓글 수: 2
Roshan Swain
Roshan Swain 2022년 5월 2일
Hi,
I am not able to run the following code snippet due to few unrecognized code variables or functions like "cirCenTr", so sharing the proper code snippet might help a bit.
Also, as you are trying to store the x and y values in a "current" variable, that can be done easily as you are already computing x and y values in the second for loop. By simply caching the values in a vector of size(cirCenTr,1), you can store them[ inside the second for loop].
If the above method does not work, share the code snippet if possible for me to take a closer look.
Steven D
Steven D 2022년 5월 2일
Thanks for your input Roshan. I tried caching the x and y values (as you mentioned), but it only yields 20 pairs (see attached image), and there should be coordinates for 108 vertices. Please let me know if you should need any other files. Thanks again for your help!

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

답변 (1개)

Roshan Swain
Roshan Swain 2022년 5월 4일
편집: Roshan Swain 2022년 5월 4일
Hi Steven,
As suggested the simplest solution would be to cache the values. In your case you are only able to cache 20x2 values. The behaviour is given due to this part of the code.
>> crDrTmp=zeros(20,2);
This creates a matrix of 20x2 size which is further used for the "x" and "y" values.
In your attached script, you are using
>> Coords = [x,y];
to cache the values. This gets updated at every iteration of the loop and the size remains 20x2.
You need to concatenate them before they gets updated. This can be done fairly simply by creating a temp matrix which stores the current values and a resultant matrix which stores the final result.
>> Result = []; % define this outside the loop.
>> Result = [Result ; Coords]
Hope this helps.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by