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

 채택된 답변

Star Strider
Star Strider 2020년 2월 2일

0 개 추천

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

Sho Gan
Sho Gan 2020년 2월 2일
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?
Star Strider
Star Strider 2020년 2월 2일
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.
Sho Gan
Sho Gan 2020년 2월 2일
error.PNG
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).
Sho Gan
Sho Gan 2020년 2월 2일
thank you very much it works perfect :)
Star Strider
Star Strider 2020년 2월 2일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2020년 2월 2일

댓글:

2020년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by