필터 지우기
필터 지우기

adding legend that is comes from a variable

조회 수: 4 (최근 30일)
Benjamin
Benjamin 2019년 3월 6일
댓글: Stephen23 2021년 5월 13일
I have a variable that looks like this:
eta = [0.4843 0.3927];
Note that I access both of these later in a loop.
How can I create a legend after my plot command to automatically make the first one the first eta entry (0.4843) and the second line in the plot to be the second eta entry (0.3928)? How can I do this dynamically so that it is automated if I change the values in eta or if I make it have more numbers?
  댓글 수: 2
Kevin Phung
Kevin Phung 2019년 3월 6일
is it not already doing that?
Benjamin
Benjamin 2019년 3월 6일
Currently, I have no legend. I could create a legend like:
legend('0.4843','0.3927')
but how can I make it so that the legend just reads in the eta variable?

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

채택된 답변

dpb
dpb 2019년 3월 6일
LEGEND() requires text, not numeric data for the legend text...
hL=legend(num2str(eta(:),'%.4f')); % salt format string to taste...
NB: must orient eta as column vector to not run the strings together horizontally all into one...
  댓글 수: 3
Mohammadsadegh araghizadeh
Mohammadsadegh araghizadeh 2021년 5월 13일
Thank you so much!
Stephen23
Stephen23 2021년 5월 13일
Since R2016b using the string class is simpler:
eta = [0.4843,0.3927];
legend(string(eta))

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

추가 답변 (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