How can I create a legend for an event data plot?

조회 수: 10 (최근 30일)
Erica Kamphorst
Erica Kamphorst 2020년 6월 10일
댓글: Adam Danz 2020년 6월 12일
I have created plots for event time-series data. The input data consists of csv files with 3 colums: onsett time, ofsett time, code (integers, from 1-9). I have first created a color array, to assign a color to each code, which looks something like this:
momAffectcolor={1, [RGB triplet];
2, (RGB triplet]; etc}
Following is a for loop that loops through each code consecutively, graps the right color from the color array, and plots the code at the right time (from onsett to ofsett). Now, I would like to create a legend for this plot based on the color array, but have not succeeded to do so. Any ideas are welcome!

채택된 답변

Adam Danz
Adam Danz 2020년 6월 10일
The easiest method IMO is to use the DisplayName property of (most) graphics objects.
It defines all of the legend strings before the loop and then applies the legend strings within the loop.
Alternatively, you could build the legend strings within the loop using sprintf() or compose().
  댓글 수: 4
Erica Kamphorst
Erica Kamphorst 2020년 6월 12일
Thank you very much! I know it is not 'cool' to use this word, but it is very cool to see that it works!
Adam Danz
Adam Danz 2020년 6월 12일
"Cool" is still a cool word ;)
"Rad", on the other hand, might be outdated :D
If you have any problems with the the legendUnq function, please let me know. If it works well, you can support it by leaving a rating on the file exchange.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by