필터 지우기
필터 지우기

Creation of a legend of a graph with a for loop

조회 수: 4 (최근 30일)
Emilio Pulli
Emilio Pulli 2021년 11월 18일
댓글: Star Strider 2021년 11월 20일
I have a graph containing different curves obtained at different velocities and I need a legend linking each curve to the relative velocity at which it has been obtained. Can I create the legend of the graph with this kind of loop without typing an infinite line containing the values of all the velocities?
for l=1:length(v)
legend([num2str(v(l)),'m/s '])
end

채택된 답변

Star Strider
Star Strider 2021년 11월 18일
The problem description is a bit difficult to interpret, however there are at least two possible solutions (if I interpret it correctly).
The first is described in the legend documentation section on Specify Legend Labels During Plotting Commands
The second is described in the legend documentation on Included Subset of Graphics Objects in Legend
I believe one of these (if not both) should work. If there are problems, post back.
Note that the 'DisplayName' option also permits using sprintf to change the display name appropriately with respect to the numeric arguments in the plot call.
.
  댓글 수: 4
Emilio Pulli
Emilio Pulli 2021년 11월 20일
Thanks man, really really appreciated!
Star Strider
Star Strider 2021년 11월 20일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by