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
2013-2-16
编辑:Azzi Abdelmalek
2013-2-16
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!