# I have tried many different ways of plotting but it won't make a line graph can someone help me out?

1 view (last 30 days)

Show older comments

##### 3 Comments

dpb
on 26 Jun 2022

### Answers (2)

Voss
on 26 Jun 2022

Edited: Voss
on 26 Jun 2022

Either:

n = 100;

for i = 1:n

x = rand();

% ...

% ...

% plot(n,x);

plot(i,x,'.'); % use a data marker to see the point,

hold on % and hold on for the next point

end

Or:

n = 100;

for i = 1:n

% x = rand();

x(i) = rand(); % collect all x values in a vector

% ...

% ...

% plot(n,x);

end

plot(1:n,x); % and plot all the points after the loop

##### 0 Comments

DGM
on 26 Jun 2022

Edited: DGM
on 26 Jun 2022

You are creating a plot object that contains only one point, but have no specified marker style to indicate those points. There is a line style implicitly specified, but there is no line plotted because there are no lines.

There is only one plot object because each new point replaces the last one. Use hold on to include more than one graphics object in an axes -- or better, don't do the plotting in the loop.

It's a common question.

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!