Clear Filters
Clear Filters

How can I draw a trajectory like this?

2 views (last 30 days)
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*')

Accepted Answer

Image Analyst
Image Analyst on 28 Jun 2017
Use 'r-' instead of 'r*'.
  3 Comments
Image Analyst
Image Analyst on 28 Jun 2017
Edited: Image Analyst on 28 Jun 2017
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 on 2 Jul 2017
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

Sign in to comment.

More Answers (0)

Categories

Find more on WSNs in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!