Doubt with plot legend

조회 수: 3 (최근 30일)
Vicente
Vicente 2015년 4월 7일
댓글: Image Analyst 2015년 4월 9일
I want to plot a graph consisting of ten different sets of data of the same entity, measured in 10 different initial conditions. I have all the data I need, and I am able to plot the graphs and select color and line styles as I want, but when I try to include a legend in the plot, it gets a bit tricky. The goal is to be able to have a dynamic legend, that automatically includes all the ammount of curves I want to plot, in case these should change number over time.
For the time being, I'm plotting 10 curves, so saying legend(1,2,3,4,5,6,7,8,9,10) is simple. But what if I want MATLAB to recognize the number of plots I want to make, identify each of the different names, and then legend the curves accordingly? What do I need to know in order to do that?
Thank you.

채택된 답변

Image Analyst
Image Analyst 2015년 4월 7일
Use a cell array to make up a custom list of strings you want displayed in the legend. I don't know what you want each one to be but you might be able to use sprintf().
  댓글 수: 8
Vicente
Vicente 2015년 4월 9일
The reason why I used %f as it was in your code, is because I really don't have a clue what does this designation do. What is %f, %7.3f, %11.3g? How are they supposed to be used? I tried typing "help %f" on command window, but as it's not a command, it didn't show any results.
Image Analyst
Image Analyst 2015년 4월 9일
Look up sprintf() in the help
MATLAB -> Language Fundamentals -> Data Types -> Characters and Strings -> Create and Concatenate Strings -> sprintf
There is a discussion of them there.

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

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