Why won't my plot graph a line?

2 次查看(过去 30 天)
for r = 1:rows
hold on
%THIS IS THE PLOT THAT WON'T CONNECT EACH POINT. IT ONLY DISPLAYS THE 'b*'
plot (averageline(2,r),averageline(1,r),'b*',averageline(2,r),averageline(1,r),'b-')
fplot(@(x)[7*sin(x)-3*x^2+11*cos(x^3)+47*x-25],[0,2],'r')
end
legend('Raw Data','Point Marker','Math Expression')
%for r = 1:rows
  3 个评论
John D'Errico
John D'Errico 2016-5-2
No. I don't think I need to see your functions. Your problem here was just that the call to plot needed to be one single call with vector arguments. MATLAB is naturally a vector/array language. Once you get used to working with vectors and arrays directly instead of loops, you will find your code becomes easier to read and write. It will work faster. Lots of gain there as you become more experienced in the language.

请先登录,再进行评论。

采纳的回答

John D'Errico
John D'Errico 2016-5-2
Note that IF you want to plot a BLUE line connecting the points, with * symbols at the data points, then it is sufficient to call plot as:
plot(x,y,'b*-')
For example,
plot(rand(1,10),rand(1,10),'b*-')
Ok, so that is a minor issue, sort of. But the real reason why your plot fails is every call that you make to plot, you are just plotting a SINGLE point.
Instead, drop the loop! Call plot ONCE.
plot(averageline(2,:),averageline(1,:),'b*-')
Or, you can do the plot as you did originally, as effectively two separate "curves".
plot(averageline(2,:),averageline(1,:),'b*',averageline(2,:),averageline(1,:),'b-')
By passing in an entire vector of points, plot will now do as you wish. You can then use hold to add the function plot.

更多回答(0 个)

类别

Help CenterFile 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