Info

この質問は閉じられています。 編集または回答するには再度開いてください。

What's the error in this program

1 回表示 (過去 30 日間)
Syed Muhammad Umar
Syed Muhammad Umar 2015 年 10 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
x=0;
dt=1;
while x<=120
y=325*x;
x=x+dt;
plot(x,y)
end
title('Mothly loan vs commulative payment');
xlabel('Monthly loan' );
ylabel('Commulative payment' );

回答 (2 件)

Star Strider
Star Strider 2015 年 10 月 6 日
It’s generally not a good idea to put a plot in a loop (unless you want to animate the plot).
This seems to work:
x=0;
dt=1;
k1 = 1;
while x<=120
y(k1)=325*x(end);
x(k1)=x(end)+dt;
k1 = k1 + 1;
end
plot(x,y)
title('Mothly loan vs commulative payment');
xlabel('Monthly loan' );
ylabel('Commulative payment' );

Image Analyst
Image Analyst 2015 年 10 月 6 日
You didn't index x or y inside the loop. But better yet, why not just vectorize it, and not even use a while loop?
dt=1;
x = 0 : dt : 120;
y=325*x;
plot(x,y, 'b.-');
grid on;
title('Mothly loan vs commulative payment');
xlabel('Monthly loan' );
ylabel('Commulative payment' );

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by