How to plot this graph?
1 view (last 30 days)
Show older comments
VALARMATHY K
on 26 Oct 2017
Commented: VALARMATHY K
on 26 Oct 2017
This is my code i am getting output, but i want to simply this because if i have to change the plotting interval i have to change the code please.... any one help me to plot this graph............
x1= [-30 30];
y1=[30 30];
plot(x1,y1,'Linewidth',3);
hold on;
x2=[-30 30];
y2=[-30 -30];
plot(x2,y2,'Linewidth',3);
hold on;
x3=[30 30];
y3=[-30 30];
plot(x3,y3,'Linewidth',3);
hold on;
x4=[-30 -30];
y4=[-30 30];
plot(x4,y4,'Linewidth',3);
hold on;
xlim([-40, 40]);
ylim([-40, 40]);
pause(1);
if(I==1);
x1=-30;
y1=30;
pause(1);
p0=plot(x1,y1,'r*','linewidth',8);
I=I+1;
end
if(I==2);
x=-25;
y=30;
hold on;
pause(1);
p1=plot(x,y,'r*','linewidth',8);
set(p0,'Visible','off');
I=I+1;
end
if(I==3);
x1=-20;
y1=30;
pause(1);
p2=plot(x1,y1,'r*','linewidth',8);
set(p1,'Visible','off');
I=I+1;
end
if(I==4);
x1=-15;
y1=30;
pause(1);
p3=plot(x1,y1,'r*','linewidth',8);
set(p2,'Visible','off');
I=I+1;
end
if(I==5);
x1=-10;
y1=30;
pause(1);
p4=plot(x1,y1,'r*','linewidth',8);
set(p3,'Visible','off');
I=I+1;
end
if(I==6);
x1=-5;
y1=30;
pause(1);
p5=plot(x1,y1,'r*','linewidth',8);
set(p4,'Visible','off');
I=I+1;
end
if(I==7);
x1=0;
y1=30;
pause(1);
p6=plot(x1,y1,'r*','linewidth',8);
set(p5,'Visible','off');
I=I+1;
end
if(I==8);
x1=5;
y1=30;
pause(1);
p7=plot(x1,y1,'r*','linewidth',8);
set(p6,'Visible','off');
I=I+1;
end
if(I==9);
x1=10;
y1=30;
pause(1);
p8=plot(x1,y1,'r*','linewidth',8);
set(p7,'Visible','off');
I=I+1;
end
if(I==10);
x1=15;
y1=30;
pause(1);
p9=plot(x1,y1,'r*','linewidth',8);
set(p8,'Visible','off');
I=I+1;
end
if(I==11);
x1=20;
y1=30;
pause(1);
p10=plot(x1,y1,'r*','linewidth',8);
set(p9,'Visible','off')
I=I+1;
end
if(I==12);
x1=25;
y1=30;
pause(1);
p11=plot(x1,y1,'r*','linewidth',8);
set(p10,'Visible','off');
I=I+1;
end
if(I==13);
x1=30;
y1=30;
pause(1);
p12=plot(x1,y1,'r*','linewidth',8);
set(p11,'Visible','off');
I=I+1;
end
if (I==14);
x1=30;
y1=30;
p13=plot(x1,y1,'r*','linewidth',8);
set(p12,'Visible','off');
I=I+1;
end
if(I==15);
x=30;
y=25;
hold on;
pause(1);
p14=plot(x,y,'r*','linewidth',8);
set(p13,'Visible','off');
I=I+1;
end
if(I==16);
x1=30;
y1=20;
pause(1);
p15=plot(x1,y1,'r*','linewidth',8);
set(p14,'Visible','off');
I=I+1;
end
if(I==17);
x1=30;
y1=15;
pause(1);
p16=plot(x1,y1,'r*','linewidth',8);
set(p15,'Visible','off');
I=I+1;
end
if(I==18);
x1=30;
y1=10;
pause(1);
p17=plot(x1,y1,'r*','linewidth',8);
set(p16,'Visible','off');
I=I+1;
end
if(I==19);
x1=30;
y1=5;
pause(1);
p18=plot(x1,y1,'r*','linewidth',8);
set(p17,'Visible','off');
I=I+1;
end
if(I==20);
x1=30;
y1=0;
pause(1);
p19=plot(x1,y1,'r*','linewidth',8);
set(p18,'Visible','off');
I=I+1;
end
if(I==21);
x1=30;
y1=-5;
pause(1);
p20=plot(x1,y1,'r*','linewidth',8);
set(p19,'Visible','off')
I=I+1;
end
if(I==22);
x1=30;
y1=-10;
pause(1);
p21=plot(x1,y1,'r*','linewidth',8);
set(p20,'Visible','off');
I=I+1;
end
if(I==23);
x1=30;
y1=-15;
pause(1);
p22=plot(x1,y1,'r*','linewidth',8);
set(p21,'Visible','off');
I=I+1;
end
if(I==24);
x1=30;
y1=-20;
pause(1);
p23=plot(x1,y1,'r*','linewidth',8);
set(p22,'Visible','off')
I=I+1;
end
if(I==25);
x1=30;
y1=-25;
pause(1);
p24=plot(x1,y1,'r*','linewidth',8);
set(p23,'Visible','off');
I=I+1;
end
if(I==26);
x1=30;
y1=-30;
pause(1);
p25=plot(x1,y1,'r*','linewidth',8);
set(p24,'Visible','off');
I=I+1;
end
if (I==27);
x1=30;
y1=-30;
p261=plot(x1,y1,'r*','linewidth',8);
set(p25,'Visible','off');
I=I+1;
end
if (I==28);
x1=25;
y1=-30;
pause(1);
p26=plot(x1,y1,'r*','linewidth',8);
set(p261,'Visible','off');
I=I+1;
end
if(I==29);
x=20;
y=-30;
hold on;
pause(1);
p27=plot(x,y,'r*','linewidth',8);
set(p26,'Visible','off');
I=I+1;
end
if(I==30);
x1=15;
y1=-30;
pause(1);
p28=plot(x1,y1,'r*','linewidth',8);
set(p27,'Visible','off');
I=I+1;
end
if(I==31);
x1=10;
y1=-30;
pause(1);
p29=plot(x1,y1,'r*','linewidth',8);
set(p28,'Visible','off');
I=I+1;
end
if(I==32);
x1=5;
y1=-30;
pause(1);
p30=plot(x1,y1,'r*','linewidth',8);
set(p29,'Visible','off');
I=I+1;
end
if(I==33);
x1=0;
y1=-30;
pause(1);
p31=plot(x1,y1,'r*','linewidth',8);
set(p30,'Visible','off');
I=I+1;
end
if(I==34);
x1=-5;
y1=-30;
pause(1);
p32=plot(x1,y1,'r*','linewidth',8);
set(p31,'Visible','off');
I=I+1;
end
if(I==35);
x1=-10;
y1=-30;
pause(1);
p33=plot(x1,y1,'r*','linewidth',7);
set(p32,'Visible','off')
I=I+1;
end
if(I==36);
x1=-15;
y1=-30;
pause(1);
p34=plot(x1,y1,'r*','linewidth',8);
set(p33,'Visible','off');
I=I+1;
end
if(I==37);
x1=-20;
y1=-30;
pause(1);
p35=plot(x1,y1,'r*','linewidth',8);
set(p34,'Visible','off');
I=I+1;
end
if(I==38);
x1=-25;
y1=-30;
pause(1);
p36=plot(x1,y1,'r*','linewidth',8);
set(p35,'Visible','off')
I=I+1;
end
if(I==39);
x1=-30;
y1=-30;
pause(1);
p37=plot(x1,y1,'r*','linewidth',8);
set(p36,'Visible','off');
I=I+1;
end
if(I==40);
x1=-30;
y1=-30;
p38=plot(x1,y1,'r*','linewidth',8);
set(p37,'Visible','off');
I=I+1;
end
if (I==41);
x1=-30;
y1=-25;
pause(1);
p39=plot(x1,y1,'r*','linewidth',8);
set(p38,'Visible','off');
I=I+1;
end
if(I==42);
x=-30;
y=-20;
hold on;
pause(1);
p40=plot(x,y,'r*','linewidth',8);
set(p39,'Visible','off');
I=I+1;
end
if(I==43);
x1=-30;
y1=-15;
pause(1);
p41=plot(x1,y1,'r*','linewidth',8);
set(p40,'Visible','off');
I=I+1;
end
if(I==44);
x1=-30;
y1=-10;
pause(1);
p42=plot(x1,y1,'r*','linewidth',8);
set(p41,'Visible','off');
I=I+1;
end
if(I==45);
x1=-30;
y1=-5;
pause(1);
p43=plot(x1,y1,'r*','linewidth',8);
set(p42,'Visible','off');
I=I+1;
end
if(I==46);
x1=-30;
y1=0;
pause(1);
p44=plot(x1,y1,'r*','linewidth',8);
set(p43,'Visible','off');
I=I+1;
end
if(I==47);
x1=-30;
y1=5;
pause(1);
p45=plot(x1,y1,'r*','linewidth',8);
set(p44,'Visible','off');
I=I+1;
end
if(I==48);
x1=-30;
y1=10;
pause(1);
p46=plot(x1,y1,'r*','linewidth',8);
set(p45,'Visible','off');
I=I+1;
end
if(I==49);
x1=-30;
y1=15;
pause(1);
p47=plot(x1,y1,'r*','linewidth',8);
set(p46,'Visible','off');
I=I+1;
end
if(I==50);
x1=-30;
y1=20;
pause(1);
p48=plot(x1,y1,'r*','linewidth',8);
set(p47,'Visible','off');
I=I+1;
end
if(I==51);
x1=-30;
y1=25;
pause(1);
p49=plot(x1,y1,'r*','linewidth',8);
set(p48,'Visible','off');
I=I+1;
end
if(I==52);
x1=-30;
y1=30;
pause(1);
p50=plot(x1,y1,'r*','linewidth',8);
set(p49,'Visible','off');
I=I+1;
end
0 Comments
Accepted Answer
Michael Madelaire
on 26 Oct 2017
Hi, hope this is what you wanted. It is still rough, but you can always make it better :)
I = 1;
x1= [-30 30];
y1=[30 30];
plot(x1,y1,'Linewidth',3);
hold on;
x2=[-30 30];
y2=[-30 -30];
plot(x2,y2,'Linewidth',3);
x3=[30 30];
y3=[-30 30];
plot(x3,y3,'Linewidth',3);
x4=[-30 -30];
y4=[-30 30];
plot(x4,y4,'Linewidth',3);
xlim([-40, 40]);
ylim([-40, 40]);
pause(1);
x = -30; y = 30;
p = plot(x, y, 'r*', 'LineWidth', 8);
for I = 1:48;
if I < 13
dx = 5; dy = 0;
elseif I < 25
dx = 0; dy = -5;
elseif I < 37
dx = -5; dy = 0;
else
dx = 0; dy = 5;
end
x = x + dx;
y = y + dy;
pause(1);
p1 = plot(x, y, 'r*', 'LineWidth', 8);
set(p, 'Visible', 'off');
p = p1;
end
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!