フィルターのクリア

object properties treated as structures

2 ビュー (過去 30 日間)
pfb
pfb 2015 年 4 月 14 日
コメント済み: pfb 2015 年 4 月 14 日
Hi all,
I always thought that you should use get and set to play with object properties.
From time to time I stumble on a strange syntax. I did not keep track of the places where I saw that, but it definitely happened to me quite a few times. One example in this respect can be found in a recent post here on matlab central.
What I'm talking about is something like
h.XData = [1 2 3];
as opposed to
set(h,'Xdata',[1 2 3]);
Is the first syntax a real thing? I tried that, but only got the expected "Attempt to reference field of non-structure array."
I'm asking because, maybe, I could find such a syntax useful in some cases.
For instance, sometimes I need to adjust the position of an axis. Perhaps reducing its width from the default 0.7750 to 0.75. What I do is
p=get(gca,'position');
p(3) = 0.75;
set(gca,'position',p);
Perhaps, if the above syntax was real, I could go
gca.position(3)=0.75;
Anyway, is there a way to change "in place" just one of the elements of a vector attribute of some object?

採用された回答

Guillaume
Guillaume 2015 年 4 月 14 日
You must be using a version of matlab older than R2014b. In R2014b, the graphics have been overhauled and are now object oriented.
See this page detailing the changes. The first syntax is valid in HG2 and is actually nicer, since you get automatic tab completion of the property name (rather than having to remember a string).
  3 件のコメント
Guillaume
Guillaume 2015 年 4 月 14 日
編集済み: Guillaume 2015 年 4 月 14 日
Yes, and no. You can't chain object properties (such as Position) to functions (such as gca) return values. That's a limitation of matlab. Also the properties are now case sensitive. So the following would work:
ax = gca; %returns the current Axes object
ax.Position(3) = 0.75; %change its width
pfb
pfb 2015 年 4 月 14 日
Yes, I worried that this would not work with gca directly. But it's cool all the same.
Thanks a lot!

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

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by