I need to have (x, y) coordinates stored in a column of a current variable
11 views (last 30 days)
Show older comments
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 Comments
Roshan Swain
on 2 May 2022
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.
Answers (1)
Roshan Swain
on 4 May 2022
Edited: Roshan Swain
on 4 May 2022
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.
0 Comments
See Also
Categories
Find more on Logical 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!