I can't plot during my loop! Help!

1 回表示 (過去 30 日間)
Bikram Singh
Bikram Singh 2016 年 3 月 2 日
コメント済み: Walter Roberson 2016 年 3 月 2 日
if true
disp('Question 3')
nMAX = input('Enter nMAX');
sumX=0;
i=1;
while i<=nMAX
plot(i,sumX); hold on
sumX = sumX + 1/i^2;
i=i+1;
end
disp('The sum of the series is');
disp(sumX);
disp('END Question 3');
end
The above is my code, when I try to plot, nothing appears. Im new to matlab so go easy lol. I would like to put sumx against i for 1:50. Thanks.

回答 (1 件)

Konstantinos Sofos
Konstantinos Sofos 2016 年 3 月 2 日
Hi you could use
plot(i,sumX,'k*'); % set black asterisk
  4 件のコメント
Bikram Singh
Bikram Singh 2016 年 3 月 2 日
So, how would I adjust the code to make this happen? Sorry, very new to Matlab.
Walter Roberson
Walter Roberson 2016 年 3 月 2 日
That is the adjusted code that Konstantinos posted.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by