Plot/Animating multiple lines on matlab at the same time?

9 ビュー (過去 30 日間)
Meryem selin Akkiz
Meryem selin Akkiz 2020 年 5 月 25 日
回答済み: Srivardhan Gadila 2020 年 5 月 28 日
I want to plot 4 lines at the same time on Matlab. I konw the initial points and final points. I want this pink box (fig.1) to move to given coordinates like an animation, however I can't plot the lines at the same time. Here is the code that were written. I only added the code for 1 cable the rest for the 3 cable is the same. How can I plot these lines at the same time?
A1= [0 0];
%intial end effector coordinates%
x_int=20;
y_int=20;
%final end effector coordinates%
x_fin=50;
y_fin=40;
%CABLE 1 coordinates%
x1_int=x_int-5; y1_int=y_int-5;
x1_fin=x_fin-5; y1_fin=y_fin-5;
%line%
m1 = abs(y1_fin-y1_int)/abs(x1_fin-x1_int);
l1= line([A1(1) x1_int], [A1(2) y1_int])
%cable 1 simulation%
for x1 = x1_int:1:x1_fin
y1=m1*abs(x1-x1_int)+y1_int
P1= [x1 y1]
path_1= line([A1(1) P1(1)],[A1(2) P1(2)]);
pause(0.001);
delete(l1)
delete(path_1)
if x1==x1_fin
plot ([A1(1) P1(1)],[A1(2) P1(2)])
hold on
end
end

回答 (1 件)

Srivardhan Gadila
Srivardhan Gadila 2020 年 5 月 28 日
From the above code I see that plot ([A1(1) P1(1)],[A1(2) P1(2)]) is called only when x1 reaches it's final iteration value. So if you are having all the A1, P1, A2, P2, ... values and you want to plot all the lines at once then you can use the plot command as follows:
plot([A1(1) P1(1)],[A1(2) P1(2)],[A2(1) P2(1)],[A2(2) P2(2)],[A3(1) P3(1)],[A3(2) P3(2)],[A4(1) P4(1)],[A4(2) P4(2)])
If this is not what you are looking then can you explain your issue in more detail and also the following part of your code
y1=m1*abs(x1-x1_int)+y1_int
P1= [x1 y1]
path_1= line([A1(1) P1(1)],[A1(2) P1(2)]);
pause(0.001);
delete(l1)
delete(path_1)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by