# add circles to starting and ending point of a line

18 Ansichten (letzte 30 Tage)
Locks am 17 Nov. 2014
Kommentiert: Locks am 18 Nov. 2014
Hi,
I am looking for a way to add a circle at both Ends of a line, as done manually in the Picture shown in the Appendix.
In Addition, I would also like to add such a circle in the middle of the line (at x=9) for both the cruve and the staigth line, in order to Show the convexity and therefore the value of the Point on the line being larger than the one on the curve
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Siam am 17 Nov. 2014
x = [1 17];
y= [19.99 18.57];
line(x,y,'Color','r','LineWidth',4)
centerX = 1;
centerY = 19.99;
'Curvature',[1,1],...
'FaceColor','r');
axis square;
centerX = (1+17)/2;
centerY = (19.9+18.57)/2;
'Curvature',[1,1],...
'FaceColor','r');
axis square;
centerX = 17;
centerY = 18.57;
'Curvature',[1,1],...
'FaceColor','r');
axis square;
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Locks am 18 Nov. 2014
thanks, this is working perfectly.

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

David Young am 17 Nov. 2014
Here is some test data, to make a plot that looks a bit like yours:
x = 2:0.1:18;
y1 = 20 - 0.05 * x;
y2 = y1 - 0.2 * sin((x-2)*pi/16);
and this draws the line graph, with the colour specified:
plot(x, y1, 'k-', x, y2, 'b-');
Now we need the index of the arrays that corresponds to x=9. Here is one way - it finds the index for the nearest point to x=9. A different approach may be needed for your data, depending on how it is represented:
[~, index9] = min(abs(x-9));
We want circles at the start point, end point and x=9 points, so we can make an array of these indexes:
indexCircle = [1 index9 length(x)];
Finally, we can use plot to draw the circles where they are needed, with the appropriate colours. Note that three circles are drawn for each graph, but of course at the ends the pairs of circles are superimposed. We need to switch hold on to keep the old graph:
hold on;
plot(x(indexCircle), y1(indexCircle), 'ko', x(indexCircle), y2(indexCircle), 'bo');
hold off;
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Locks am 17 Nov. 2014
sorry to bother you but could you tell me what I Need to adjust in the code so it's working also with line?
David Young am 17 Nov. 2014
You use line to draw the line plots, so that replaces the first call to plot in my code. You then draw the circles using the second call to plot, or something similar.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by