number coding the plot beside color coding

Hi all,
I am looking for a way to insert number coding of both the legend and the curves of the a graph with plot command. like attached figure ( I added numbers manually) do you know any way to do that. thanks for your time and help.number_coding plot.png

 Risposta accettata

It is likely not possible to do exactly that, however you can come close.
Try this:
x = [1 10 14 17];
y = randi([-40 -11], 4, 6);
figure
plot(x, y, '.-')
text(ones(1, size(y,2)), y(1,:), compose('%d', 1:size(y,2)))
lgndc = compose('%d Curve %d', (1:size(y,2)).'*[1 1]);
legend(lgndc, 'Location','SW')
ylim([-45 max(ylim)])
You will need to produce your own version of ‘lgndc’. Just precede each entry by the number of the curve.

6 Commenti

thanks Star Strider, when I run your code I get the following error for the text(...) command:
" String argument expected after 2 or 3 numeric arguments"
any idea where does it come from?
My pleasure.
I get no errors when I run it.
Please post the complete error message (all the red text), including the line that threw that error.
I changed compose to sprintfc (undocumented, everyone has it).
Try this:
x = [1 10 14 17];
y = randi([-40 -11], 4, 6);
figure
plot(x, y, '.-')
text(ones(1, size(y,2)), y(1,:), sprintfc('%d', 1:size(y,2)))
lgndc = sprintfc('%d Curve %d', (1:size(y,2)).'*[1 1]);
legend(lgndc, 'Location','SW')
ylim([-45 max(ylim)])
Again, it ran for me without error (R2019b).
thank you very much it works perfect :)
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by