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

5 ビュー (過去 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 件のコメント
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.

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by