How can I set the labels of multiple axes without iteration?

2 ビュー (過去 30 日間)
Yazan
Yazan 2021 年 6 月 28 日
コメント済み: Cam Salzberger 2021 年 7 月 7 日
Hello all,
I have a figure with multiple uipanels, each with its own axes. How can I set the labels of all the pannels' axes at once without having to use iterations? I am assuming that the axes of all pannels should have the same label.
Thanks!

採用された回答

Cam Salzberger
Cam Salzberger 2021 年 6 月 28 日
Hello Yazan,
If, as you create the axes, you save the handles to one reference axes array, you can easily set the labels like so:
xlabel(axesArray, "LabelX")
ylabel(axesArray, "LabelY")
If you don't have an array of axes, and it's not feasible to get one while setting up the figures, you can use findobj to get that list:
axesArray = findobj(figureHandle, "Type", "axes");
This searches all nested children by default, though you can set limits on that.
-Cam
  4 件のコメント
Yazan
Yazan 2021 年 6 月 30 日
Hello Cam. I am using R2019b. I am getting the following error message:
Incorrect number of input arguments.
Cam Salzberger
Cam Salzberger 2021 年 7 月 7 日
Well, it looks like they made xlabel vectorized at some point, but not in R2019b. So here's a quick workaround, if you don't want to use loops.
allAxes = [ax1, ax2];
% or
allAxes = findobj(f, 'Type', 'axes');
arrayfun(@(hAx) xlabel(hAx, 'XLabel'), allAxes)
-Cam

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by