Maryam Seraj
Maryam Seraj

Reputation: 11

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?

Upvotes: 1

Views: 136

Answers (2)

Artezanz
Artezanz

Reputation: 126

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])

Upvotes: 2

Chris
Chris

Reputation: 62

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

Upvotes: 0

Related Questions