Single legend entry for a line with endpoints.

1 view (last 30 days)
I would like to display one of my legend entries as a red line with '*' at the end points as the red line is in the figure or a line with '*' in the center would work as well. I have tried several methods but they end up changing all entries or don't give the output I want.
This is for the 'Max Cycle Variation' entry. Any help would be very appriciated.
  1 Comment
Mann Baidi
Mann Baidi on 10 Nov 2023
Hi
Have you tried this method?
x=0:5;
y=5:-1:0;
plot(x,y,'y-')
hold on
plot(x(5),y(5),'r*')
plot(x(3),y(3),'r*')
plot(x(3:5),y(3:5),'r-')

Sign in to comment.

Accepted Answer

Voss
Voss on 10 Nov 2023
Edited: Voss on 10 Nov 2023
x=0:90;
y=30*cosd(x-30).^6-20;
plot(x,y,'-b')
hold on
x_red = x(26:36);
y_red = y(26:36);
plot(x_red,y_red,'-ro','MarkerFaceColor','r','MarkerIndices',[1 numel(x_red)]);
plot(x(31),y(31),'g*')
ylim([-20 15])
legend({'Cycles','Max Variation','Optimal'},'Location','south')

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!