How can I graph multiple loops on one graph?

Hello! I am trying to graph a nested loop, for varying values of b, looping through values of n.
Here is the program script:
p = 50;
n = 5;
for b = 0.5 : 0.9 : 1.1 : 1.5;
for i = 1 : 1 : n;
x(i) = p*(b^i);
end
end
%Plot all 5 time series on the same graph
time = 1 : 1 : 5;
plot(time,x)
When I run the program, it plots one line on the graph. Does anyone know how to make it so the graph contains five lines, one for each value of n?

 採用された回答

Thorsten
Thorsten 2015 年 9 月 22 日

0 投票

p = 50;
n = 5;
b = [0.5 0.9 1.1 1.5];
t = 1:n;
for i = t
x(i,:) = p*(b.^i);
end
plot(t,x, '-o')

1 件のコメント

Viktoria Kolpacoff
Viktoria Kolpacoff 2015 年 9 月 22 日
Thank you so much! This worked!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by