Plotting Negative Values in a Loop

2 ビュー (過去 30 日間)
Christopher Nguyen
Christopher Nguyen 2019 年 6 月 4 日
編集済み: KSSV 2019 年 6 月 4 日
Trying to plot values for a robot gripper using a for loop with a pause to get a graph that moves. Was just wondering why I can't plot these negative values.
The code used to plot was:
figure(3)
hold on
for i = 0:0.5:10
plot(x(i), y_fit(i))
pause(0.5)
hold off
end
The variables used were:
L = 1;
T = [0 2 5 8 10];
Angle = [-45 13 45 50 60];
Angle2 = [45 41 69 106 120];
a = polyfit(T, Angle, 3);
b = polyfit(T, Angle2, 3);
T = 0:0.5:10;
x = L*(cos(theta_Angle)) + L*cos((theta_Angle2));
y = L*(sin(theta_Angle)) + L*(sin(theta_Angle2));
p = polyfit(x, y, 3);
y_fit = polyval(p, x);
theta_Angle = (a(1)*(T.^3))+(a(2)*(T.^2))+(a(3)*T)+a(4);
theta_Angle2 = (b(1)*(T.^3))+(b(2)*(T.^2))+(b(3)*T)+b(4);

回答 (2 件)

KSSV
KSSV 2019 年 6 月 4 日
編集済み: KSSV 2019 年 6 月 4 日
figure(3)
hold on
for i = 1:1:10
plot(x(i), y_fit(i),'.')
pause(0.5)
end
hold off
OR
plot(x, y_fit)
  2 件のコメント
Christopher Nguyen
Christopher Nguyen 2019 年 6 月 4 日
I tried implementing this and the loop works but for some reason nothing appears on the figure except for the values constantly changing on the axis.
KSSV
KSSV 2019 年 6 月 4 日
Edited.

サインインしてコメントする。


Dennis
Dennis 2019 年 6 月 4 日
As KSSV already pointed out you need integers as array indices.
Additionally i would recommend to use markers to make your data points visible and move the 'hold off' out of the loop:
hold on
for i = 1:1:10
plot(x(i), y_fit(i),'marker','*')
pause(0.5)
end
hold off

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by