How can I change the last marker of a line to a different style?

6 visualizzazioni (ultimi 30 giorni)
I have a plot where I want to change the last data point to a different marker style and marker size. In the plot below, I want the first 6 markers to be '*', and the last marker to be 'x'.
x = [0 7500 15000 22500 30000 36215 42433];
y = [114.8 112.4 105.5 103.4 103.6 101.9 91.8];
plot(x,y,'-*')
xlim([0 45000])
ylim([80 125])
xlabel('x')
ylabel('y')
grid on

Risposta accettata

Arif Hoq
Arif Hoq il 4 Feb 2022
x = [0 7500 15000 22500 30000 36215 42433];
y = [114.8 112.4 105.5 103.4 103.6 101.9 91.8];
plot(x,y,'-o','MarkerIndices',1:6)
hold on
plot(x,y,'-x','MarkerIndices',7)
xlim([0 45000])
ylim([80 125])
xlabel('x')
ylabel('y')
grid on

Più risposte (2)

Davide Masiello
Davide Masiello il 4 Feb 2022
x = [0 7500 15000 22500 30000 36215 42433];
y = [114.8 112.4 105.5 103.4 103.6 101.9 91.8];
plot(x(1:end-1),y(1:end-1),'-b*',x(end-1:end),y(end-1:end),'-b')
hold on
plot(x(end),y(end),'-bx','MarkerSize',12)
xlim([0 45000])
ylim([80 125])
xlabel('x')
ylabel('y')
grid on

Steve Tavoletti
Steve Tavoletti il 4 Feb 2022
@Davide Masiello @Arif Hoq Thank you for the quick replies!
I have a follow up question. This solution works for adding the "x" at the bottom, but it creates 2 series for each set of data. Since each pair of series refers to the same data, how can I ignore the 2nd and 4th entry when creating the legend?

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by