How determine type of plot object?
5 ビュー (過去 30 日間)
古いコメントを表示
Say, I am given an axes containing unknown plot objects. I am searching for a way to determine the type of these plot objects, i.e. I would like to know whether they are a lineseries object, a barseries object, an errorbarseries object, etc.
For core graphics objects (e.g. line, patch, surface, text,...) this isn't a problem because one can query the object's 'type' property,
get(h, 'Type').
However, most plot objects such as barseries or areaseries return 'hggroup' as type.
I have tried to find unique properties of each plot object type (e.g. 'BarPeers' for barseries objects) and then used a cascade of isprop calls to identify the plot object, but this obviously isn't very elegant.
Matlab itself seems to know the plot object type, because e.g.
set(handle_of_barseries_object, 'Color','r')
returns the error message "The name 'Color' is not an accessible property for an instance of class 'barseries'." So the plot object type must be determinable somehow.
Any ideas?
Stephan.
0 件のコメント
採用された回答
Julian Hapke
2014 年 7 月 11 日
here's the probably dirtiest code I've written so far, but does, what you want:
% make an example plot with several classes
figure;
hold on;
X=rand(10,1);Y=rand(10,1);X=sort(X);Y=sort(Y);
plot(X,Y);
errorbar(X,Y);
bar(X,Y);
barh(X,Y);
contour([X Y],[Y X]);
plts = get(gca,'Children');
% determine plot class by catching the error message that is
% generated when a nonexistent property is addressed
type = cell(size(plts));
for kk = 1:length(plts)
try
get(plts(kk),'nonexistent')
catch err
tmp = strfind(err.message,'''');
type{kk} = err.message(tmp(end-1)+1:tmp(end)-1);
end
end
regards
julian
3 件のコメント
Julian Hapke
2016 年 1 月 18 日
Addon:
From 2014b on you can use the
class(h)
function to get information about your plot handle and its class.
Julian Hapke
2016 年 3 月 14 日
編集済み: Julian Hapke
2016 年 3 月 14 日
just found out that pre 2014b
class(handle(h))
also does the trick
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!