MATLAB displays a blank graph when I plot try to plot
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
MHN
2016-2-18
It is not empty, it has the points. Do the following change:
change the plot line to
plot(di(ii),slope(ii),'o')
0 个评论
更多回答(1 个)
Renato Agurto
2016-2-18
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!