So I have a couple of figures open. Each has its uniqe name. I want to plot a line on one of them. How to select figure by his name?
Thanks.

 採用された回答

per isakson
per isakson 2012 年 11 月 9 日
編集済み: per isakson 2012 年 11 月 9 日

1 投票

Hint:
fh = findobj( 'Type', 'Figure', 'Name', 'the_name_of_the_figure' );

4 件のコメント

Tomislav
Tomislav 2012 年 11 月 9 日
That's it.
Thanks.
Royi Avital
Royi Avital 2020 年 3 月 12 日
Doesn't work for UI Figure element (MATLAB R2019b).
Steven Lord
Steven Lord 2020 年 3 月 12 日
uifigure objects have their HandleVisibility property set to 'off' and that property is read-only. As documented, "findobj does not return graphics objects that have the HandleVisibility property set to 'off'."
You'll need to use findall. Note that unlike findobj the findall function requires that you specify an object handle as the first input (it cannot accept simply a list of property name-value pairs), so you can use groot if you want to find all of them.
>> h = uifigure('Name', 'abc');
>> h2 = findall(groot, 'Type', 'figure', 'Name', 'abc');
>> isequal(h, h2)
ans =
logical
1
佳望
佳望 2025 年 8 月 2 日
it should be noticed that, if you created a figure without giving its name, its default name will be blank, 'Figure 1' is NOT its name, you can't find it by using findall with Figure 1.

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 3 月 12 日

2 投票

My approach would be to create the figure names when you create the corresponding figure.
fred = figure;
barney = figure;
Now you can go back to either figure when you need to do so. This just requires you to save those figure handles. In order to wake up fred, just do so by calling figure as needed.
figure(fred)
You might be more creative than was I in naming the figures, but you should get the idea.

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2012 年 11 月 8 日

コメント済み:

2025 年 8 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by