Why is it that Line objects can be instances of two different classes? How can I use findobj to detect only chart primitives?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Using findobj, I have ended up with two arrays of Line graphics handles,
load handleArrays
hL
hD
However, the arrays do not appear to belong to a common class,
whos hL hD
Moreover, even though hD clearly has all the same properties as hL, it cannot be accessed with standard indexing, e.g.,
isprop(hD(1),'Color')
hD.Color
What is the function of these two different handle graphics types, and how do I tell findobj to retrieve only the hL kind and not the hD kind?
3 Commenti
Fangjun Jiang
il 22 Apr 2024
Can you clarify how hD and hL are obtained, and what are you expecting? matlab.graphics.chart.primitive and matlab.graphics.primitive are packages, not class.
Risposta accettata
Steven Lord
il 22 Apr 2024
Handle Graphics objects support the creation of heterogeneous arrays. So for example you can store a figure handle and an axes handle in the same array. [This is more often used to preallocate an array of Handle Graphics objects using gobjects and storing various types of object handles inside.]
f = figure;
ax = axes;
h = [f, ax]
If you look at the class of the h it is neither Figure nor Axes; it is a common (undocumented) base class from which both Figure and Axes inherit, as per this line from the documentation for heterogeneous arrays I linked to above: "The class of a heterogeneous array is that of the most specific superclass shared by the objects of the array."
class(h)
What your code shows me is that hD is such a heterogeneous array, something along the lines of h2 in the example below:
L1 = plot(1:10);
hold on
L2 = fplot(@sin);
h2 = [L1; L2]
class(h2)
2 Commenti
Steven Lord
il 24 Apr 2024
It's true that the Figure and Axes classes each define a property named Color. But does their common base class define a Color property?
f = figure;
ax = axes;
h = [f, ax];
properties(h)
No, their common base class (matlab.graphics.Graphics) has no public properties. So the error message was accurate.
Now if we took two objects that inherit from a common base class that does have properties, like two different types of axes:
f2 = figure;
ax2 = polaraxes;
h2 = [ax, ax2]
class(h2)
Does this common base class define any public properties?
properties(h2)
Their common base class has several properties, so we can use one of those to generate a comma-separated list.
h2.Units
By default, most of their properties will happen to be the same. One that isn't in this case is Parent.
h2.Parent
Più risposte (1)
Fangjun Jiang
il 22 Apr 2024
Modificato: Fangjun Jiang
il 22 Apr 2024
load handleArrays.mat
get(hD,'Color')
get(hD,'Type')
get(hL,'Type')
class(hD)
class(hD(1))
class(hL)
class(hL(1))
class([hD,hL])
doc matlab.graphics.primitive.Data
In R2023b, it says matlab.graphics.primitive.Data is an undocumented builtin constructor.
3 Commenti
Fangjun Jiang
il 22 Apr 2024
In R2023b, it says matlab.graphics.primitive.Data is an undocumented builtin constructor.
doc matlab.graphics.primitive.Data
Fangjun Jiang
il 22 Apr 2024
For single handle, you can use .Property, like hD(1).Color. But for array of handles, I always use get(). I never thought hD.Color should work.
Vedere anche
Categorie
Scopri di più su Graphics Object Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!