Figure Properties - Syntax doubt

In Matlab help, in the Figure properties there's this example:
fig = figure;
u = fig.Units;
fig.Units = 'inches';
My question is: why do I need u = fig.Units; if I can get an handle to the properties using fig.propertie='value'?
Thank you

 採用された回答

Walter Roberson
Walter Roberson 2015 年 11 月 27 日

0 投票

In my experience, if you are changing the units at some point other than when you are creating the figure, then you are usually doing so in order to inquire what the Position is in a particular unit. As there is not a call to ask "Position in inches", you typically instead record the current units with a call such as u = fig.Units; and then change to the desired units, and then get the Position, and then change the units back to the original units with fig.Units = u;

3 件のコメント

rbarata
rbarata 2015 年 11 月 27 日
編集済み: rbarata 2015 年 11 月 27 日
I see...so, I see u = fig.Units; acts as a "quick handle" to revert to the original units. It could be done also by fig.Units = 'inches'; and then fig.Units = 'mm'. The position defined in inches is maintained, only the units are converted to mm.
Walter Roberson
Walter Roberson 2015 年 11 月 27 日
When you change Units, then Position is recalculated from the old units to the new units.
u = fig.Units;
fig.Units = 'inches';
pos = fig.Position; %gets position in inches no matter how it was originally defined
fig.Units = u; %goes back to old units
The advantage over fig.Units = 'mm' afterwards is that you not relying on the old units being 'mm'.
rbarata
rbarata 2015 年 11 月 27 日
Yes, I could be wrong... with fig.units=u; its assured the old units are used.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

タグ

質問済み:

2015 年 11 月 27 日

コメント済み:

2015 年 11 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by