简体   繁体   中英

How connect points by using plot

The problem with my code is that it plots discrete points without connecting them together.

Related code:

for i:1:100
    wx(i,1)= Related formula
    figure(1)
    plot(i,wx(i,1),'r.-')
    line(i,wx(i,1))
    axis([0,i,-10,10])
    hold on
end

Result has been shown in the image below;

How can I connect them together?

The plot function can only join points with a line if you enter all the endpoints of the line in an array. If you send them one by one, it will only plot discrete points without connecting them. It is recommended to compute all the points in the array first, before sending them all to the plot function at once.

The easiest solution here would be:

for i = 1:100
  x(i) = i
  wx(i,1) = related_formula()
end

figure(1)
plot(x, wx(:,1), 'r.-')
axis([0,i,-10,10])
i =1:100;
wx=Related formula(i);
figure(1)
plot(i,wx,'r.-')
axis([0,i,-10,10])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM