Stem(Array) is graphed wrong (off by one). Index error?

Hello This is my first post. I have created, using hist, a 1row-by-20col array with 20 numbers:
C=[.9 .1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]. This means that at position 0, the value is .9. At position 1 the value is .1 and so on. When I try to plot this array with the function "stem(C)" The graph would put the .9 value on x=1 and .1 value on x=2. It's supposed to go on x=0 and x=1 respectively. I've read about how Mathlab index starts with 1 instead of 0. Can anyone help me correct the graph? Thank you.

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 16 日
編集済み: Azzi Abdelmalek 2013 年 2 月 16 日

0 投票

C=[.9 .1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
stem(0:19,C,'r')
stem(C) % you did not specify the x-axis value. The default is 1:numel(C)

カテゴリ

ヘルプ センター および File Exchange で Language Fundamentals についてさらに検索

質問済み:

2013 年 2 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by