How can I draw a trajectory like this?

2 次查看(过去 30 天)
Hello everybody Would you help me draw a trajectory like this using sin and cos functions but not with these stars, I want it with solid and continuous line.I have found this piece of code but i couldn't get a clue. Thanks in advance.
c1=30;
c2=30;
for j=1:3
for i=1:1:8 %%%2nd for loop for no. of S in the column
if(mod(i,2)~=0) %%%for C structure and opposite C structure
th = linspace( pi/2, -pi/2, 10);
for k=1:1:length(th)
anchormove(1,idx) = r *-cos(th(k)) + c1;
anchormove(2,idx) = r *-sin(th(k)) + c2;
idx=idx+1;
end
else
th = linspace( -pi/2, pi/2, 10);
for k=1:1:length(th)
anchormove(2,idx) = r * sin(th(k)) + c2;
anchormove(1,idx) = r * cos(th(k)) + c1;
idx=idx+1;
end
end
c2=c2+60;
end
lastmove=anchormove(2,idx-1);
for i=anchormove(1,idx-1):10: anchormove(1,idx-1)+(r+60)
anchormove(1,idx) = i;
anchormove(2,idx) = lastmove;
idx=idx+1;
end
c2=450;
c1=c1+90;
for i=1:1:8 %%%2nd for loop for no. of S in the column
if(mod(i,2)~=0) %%%for C structure and opposite C structure
th = linspace( pi/2, -pi/2, 10);
for k=1:1:length(th)
anchormove(1,idx) = r *cos(th(k)) + c1;
anchormove(2,idx) = r *sin(th(k)) + c2;
idx=idx+1;
Ax=anchormove(1,i);
Ay=anchormove(2,i);
plot(Ax,Ay,'r*')

采纳的回答

Image Analyst
Image Analyst 2017-6-28
Use 'r-' instead of 'r*'.
  3 个评论
Image Analyst
Image Analyst 2017-6-28
编辑:Image Analyst 2017-6-28
Attach your code here. I'm not going out to any third party site when you can attach it here with the paper clip icon. Your code as pasted above doesn't work. There are at least 3 "end" statement missing. I don't know where to put them because the formatting and indenting is all messed up. You can type control-a then control-i to fix indenting before pasting here. Please post code that runs.
Zeinab Ahmadi93
Zeinab Ahmadi93 2017-7-2
Ok Thanks dear Image Analyst for your guidance...I corrected my code and it runs. But I have another question, Would you please help me. I posted it here
https://www.mathworks.com/matlabcentral/answers/347079-how-can-i-set-an-equal-distance-of-5-units-between-the-red-star-points

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 WSNs 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by