How can I plot graph in this relationship?

1 回表示 (過去 30 日間)
kim
kim 2023 年 10 月 31 日
編集済み: Torsten 2023 年 10 月 31 日
I'm trying to plot graph of relations of (j,s) in this for script.
s=0;
for j=1:1:10
s=s+j;
disp(['j = ', num2str(j)] );
disp(['s = ', num2str(s)] );
plot(j,s)
end
however, nothing appears when I try to plot it. What's the problem with it? And how can I plot graph of the relationship between (j,s)?

採用された回答

Torsten
Torsten 2023 年 10 月 31 日
編集済み: Torsten 2023 年 10 月 31 日
s=0;
hold on
for j=1:1:10
s=s+j;
disp(['j = ', num2str(j)] );
disp(['s = ', num2str(s)] );
plot(j,s,'b o')
end
j = 1
s = 1
j = 2
s = 3
j = 3
s = 6
j = 4
s = 10
j = 5
s = 15
j = 6
s = 21
j = 7
s = 28
j = 8
s = 36
j = 9
s = 45
j = 10
s = 55
hold off
  1 件のコメント
Torsten
Torsten 2023 年 10 月 31 日
It's more common to compute all values for s in advance and make the plot afterwards:
x = 1:10;
s = cumsum(x);
plot(x,s,'b o')

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by