# MATLAB displays a blank graph when I plot try to plot

56 views (last 30 days)
Imraan Jabar on 18 Feb 2016
Answered: Renato Agurto on 18 Feb 2016

So I am working on an assignment where we are to calculate the slope (slope=y2-y1/x2-x1)of (x^3)*cos(x) at x=3 using x2= 3.001, 3.005, 3.01,3.05, 3.1, 3.5, and 4 So wrote a for loop to calculate all the slopes and included a plot within the loop so it can plot the change in x against slope.

```x=3;
y=(x^3)*cos(x);
di(1)=0.001;
di(2)=0.005;
di(3)=0.01;
di(4)=0.05;
di(5)=0.1;
di(6)=0.5;
di(7)=1;
hold on
for ii=1:7
xi(ii)=x+di(ii);
yi=((xi(ii))^3)*cos(xi(ii));
slope(ii)=(yi-y)/di(ii);
plot(di(ii),slope(ii))
end
hold off
```

So the problem is the graph comes up as blank. I tried looking around for people having similar issue with plot but could find a good solution. Do you know what I am doing wrong?

MHN on 18 Feb 2016
It is not empty, it has the points. Do the following change:
change the plot line to
plot(di(ii),slope(ii),'o')

Renato Agurto on 18 Feb 2016

Since you are plotting single dots ( plot in a for loop) the dots aren't connected. Just try:

```x=3;
y=(x^3)*cos(x);
di(1)=0.001;
di(2)=0.005;
di(3)=0.01;
di(4)=0.05;
di(5)=0.1;
di(6)=0.5;
di(7)=1;
for ii=1:7
xi(ii)=x+di(ii);
yi=((xi(ii))^3)*cos(xi(ii));
slope(ii)=(yi-y)/di(ii);
end
```
```plot(di,slope)
```