Plotting lines between data points on a graph - PROBLEM!

2 views (last 30 days)
im facing a problem of plotting a line between points plotted on a graph. below is my code. only points appear but not the line connected them. Why is this so? This code is within a FOR loop, is that why it doesnt work?
if ((cx>=10)&(cx<=60)&(cy>=10)&(cy<=60))
figure(2);
title('Graphical Results');
hold on;
plot(j, diameter(j), 'ro-', 'LineWidth', 2, 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'g', 'MarkerSize', 10)
ylabel('Diameter of pupil');
xlabel('Frame');
hold off;
set(gcf, 'Position', get(0, 'ScreenSize'));
fprintf(1,'#%3d %11.1f %8.1f\n', j, diameter(j), area);
end
below is the graph i am getting...
you realised there isnt a line connected it.. i have tried many combinations but nothing works.

Answers (1)

Walter Roberson
Walter Roberson on 6 Mar 2012
Unless you supply at least two X and two Y coordinates to plot(), all it can do is draw the one point you give it.
You would be better off storing the j values until the end of the loop, and then
plot(Jlist, diameter(Jlist), 'ro-' <etc>)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!