Access to properties of graphic objects using dot notation on versions of Matlab before R2014b

An attempt to change the colors of the axis in the matrix graph here.


Matlab documentation link: Matlab docs on setting axis properties

Code snippet:

subplot( 'Position', [ left bottom (1/(cols*2)) (1/rows) ] ); ax = gca; ax.Color = 'y'; 

This is all but the copy and paste from the example in the docs (shown here):

enter image description here

But Matlab issues a warning and does not change the axis colors for me:

Warning. The purpose of the Struct field overrides the value of the Double class. See MATLAB R14SP2 Release Notes, Assigning Non-Structures Variables as Structures Displays a warning for more details.

I tried to assign a double, for example, 42.0, but he did not like it.

+5
source share
1 answer

Your warning message seems to indicate that you are using the version before Matlab R2014b.

If so, you do not have access to dot notation, because when you do ax=gca; , you get the return value of the ax that the double class has. The value is the identifier of the object descriptor (the current axis in this case), but not the descriptor itself.

When you try to execute ax.Color = 'y'; Matlab thinks that you want to overwrite your ax [double] new variable ax , which will be a structure, with the color field and give a warning.

You can access point notation for graphical objects and properties, but first you need to get a real object descriptor using the handle function. For instance:

 ax = handle( gca) ; %// the value "ax" returned is an `object`, not a `double` 

or even an existing link to a graphic descriptor:

 ax = gca ; %// retrieve the `double` reference to the handle ... ax = handle(ax) ; %// the value "ax" returned is an `object`, not a `double` 

then you can use dot notation for all public properties of the graphic. ax.Color = 'y'; must now be valid

+14
source

Source: https://habr.com/ru/post/1208692/


All Articles