object properties treated as structures
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Guillaume
le 14 Avr 2015
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 commentaires
Guillaume
le 14 Avr 2015
Modifié(e) : Guillaume
le 14 Avr 2015
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
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!