How can I turn legend on for UIAxes, for only one function?

6 ビュー (過去 30 日間)
Sander Janssen
Sander Janssen 2022 年 10 月 7 日
移動済み: Adam Danz 2022 年 10 月 10 日
I have made an app (GUI) that has a list of different figure functions that will plot figures to the UIAxes object when I select a function. (Each function is equal to a different plot).
I want to turn the legend on for one of those functions, which I had done with:
legend(UIAxes, 'Label1', 'Label2')
This works fine for that one function/plot, it will however also be on when I switch to another plot with the legend "data1".
I realise I could fix this by manually turning the legend off in all of the other functions. I did however wonder if there is a better way to turn the legend on for just one function/plot, so I do not have to change all the other functions (and add 'useless' code).
If my question is unclear, please let me know.

採用された回答

Mario Malic
Mario Malic 2022 年 10 月 7 日
移動済み: Adam Danz 2022 年 10 月 10 日
Hey, I would suggest the following.
  1. Create a array of graphic objects with UIAxes you want to do this operation. Use find all, or set it in the code
  2. Create a WindowsButtonDownFcn callback on UIFigure that will check for its SelectedObject property
  3. If the SelectedObject is one of the objects from the array in step 1, get its Legend property, and set its visibility to on. Do the vice-versa for the other objects from the array.
If you get stuck, post your code.
  1 件のコメント
Sander Janssen
Sander Janssen 2022 年 10 月 10 日
移動済み: Adam Danz 2022 年 10 月 10 日
Thank you, that solved my problem!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by