plotting trouble

can anyone help me see what im doing wrong here i want to plot this with a for loop
for i=1:20
x= i
y=x
end
plot(x,y)
but when i plot it,there is no graph in the figure window and the graph has a really weird range that i didnt input however when i try this it works just fine why is that
x=1:1:20
y=x
plot(x,y)

 采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-11-14

1 个投票

In your for-loop, x and y are assigned a value one at a time. x and y are always over-written. So at the end of the loop, you end up with x==20 and y==20. The plot just shows one dot.
In the second approach, x is a vector and so is y.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 2-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