How to plot the continuous linear graph of y(n) + y(n-1) + ... + y(1)

3 ビュー (過去 30 日間)
Peiman
Peiman 2024 年 10 月 25 日
編集済み: Peiman 2024 年 10 月 25 日

I have a hundred discrete values in Matlab. For example: y1=2 y2=-1 y3=1; I know how to plot each of them as dots. But I would like to have a graph of them, where for x=0 on x axis, y1=y1 itself on y axis, for x=1 on the axis y2=y2+y1, and for x=2 y3=y3+y2+y1, etc. Like this: plot(y(n+1)+y(n)+...+y(1), x(n)) That is all my question above. Imagine on first time (x=0), I have 2 apple, but on the second time(x=1) since I have eaten 1 of them (-1), then I did addition operation and 2+(-1) means 1 remained for me on 2nd time (on x=1) //// X is only 0 1 2 3 numbers on the x axis of the chart. Don't get confused, don't think about it. It's the axis of the plot to draw the y above it. Imagine the addition of y1&y2 data happens on x=1 then on x=2. x1 x2 like t1 t2... The plot is 2 dimensional not 3d. It doesn't have x y z, only x and y. x is static number on time. First time second time etc. //// All my question is simplified here: How to plot the continuous linear graph of y(n) + y(n-1) + ... + y(1)

採用された回答

Voss
Voss 2024 年 10 月 25 日
編集済み: Voss 2024 年 10 月 25 日
y = [2 -1 1 2 -1 -2 -1 2 3 -2 1];
plot(0:numel(y)-1,cumsum(y),'.-')

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by