Mohammad Ghorbani February 2016
### how i can plot a graph with inetger number as input

how i can plot `cos(3 pi/7 * n )`

such that n be integer number in interval [x=0,x=10] in matlab?
i used this code

```
figure
X = linspace(0,2*pi,10)';
Y = cos(X);
stem(X,Y)
set(gca,'xlim',[0,10])
```

the graph that i get is this , but i want to show points of graph in integer number of x axis . how can i do that ?

Instead of using linspace for such a simple example as this one, you can just define your vector `X`

as an integer vector taking steps of `1`

, from `0`

to `10`

:

```
figure
X = 0:1:10;
Y = cos(3*pi/7*X);
stem(X,Y)
set(gca,'xlim',[0,10])
```

Below shows the plot generated by the code snippet above (bottom plot) as well as the same plot using step size `0.5`

(`X = 0:0.5:10`

, top plot).

Note that as Adriaan notes in the comments below, the default step size for `... = from:stepsize:to`

notation is `1`

, i.e., if omitting the `stepsize`

and simply writing `... = from:to`

, a step size of `1`

is used by default (`stepsize=1`

).

Asked in February 2016

Viewed 3,304 times

Voted 6

Answered 1 times

Viewed 3,304 times

Voted 6

Answered 1 times