Why is it that Line objects can be instances of two different classes? How can I use findobj to detect only chart primitives?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Fangjun Jiang
2024-4-22
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.
采纳的回答
Steven Lord
2024-4-22
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 个评论
Steven Lord
2024-4-24
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
更多回答(1 个)
Fangjun Jiang
2024-4-22
编辑:Fangjun Jiang
2024-4-22
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 个评论
Fangjun Jiang
2024-4-22
In R2023b, it says matlab.graphics.primitive.Data is an undocumented builtin constructor.
doc matlab.graphics.primitive.Data
Fangjun Jiang
2024-4-22
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!