2014-10-02 88 views
2

我想逐步访问lineseries对象的'MarkerFaceColor'属性的'sub-property',名为'allowedStyles'。通过扩展'MarkerFaceColor'属性行,可以在Matlab的检查器(inspect(handle))中看到该'子属性'。如何访问Matlab的句柄对象的子属性:'allowedStyles'

我想要做类似下面的事情或者获得相应的命令。 allowedstyles = get(hh,'MarkerFaceColorAllowStyles');

Matlab的检查窗口指示我寻求的信息的屏幕截图。 https://drive.google.com/file/d/0B0n19kODkRpSRmJKbkQxakhBRG8/edit?usp=sharing

Inspection Window

更新:

用于访问通过cellstr这个信息的完整性我最终的解决办法是写了下面的函数。感谢Hoki。如果您想为诸如MarkerFaceColor之类的属性提供用户选择,则此信息(允许的样式)对于GUI非常有用,因为您不知道它们正在修改的图形对象的类型。我用这些'allowedStyles'填充一个列表框以及一个设置颜色的选项。网格图'MarkerFaceColor'允许样式{'none','auto','flat'},而系列图有{'none','auto'}。

function out = getAllowedStyles(hh,tag) % hh - handle returned from plot, surf, mesh, patch, etc % tag - the property i.e. 'FaceColor', 'EdgeColor', etc out = []; try aa = java(handle(hh(1))); bb = eval(sprintf('aa.get%s.getAllowedStyles;',tag)); bb = char(bb.toString); bb(1) = []; bb(end) = []; out = strtrim(strsplit(bb,',')); end end

+0

到目前为止你做了什么? – Leistungsabfall 2014-10-02 17:52:57

+0

没有显示你卡在哪里,很难提供帮助。 – 2014-10-02 17:56:43

+0

在Matlab的UI检查窗口中有可用的信息,我想在命令行上进行访问。 – Humberto77 2014-10-02 18:01:55

回答

3

我认为这确实是只读(或至少我无法找到正确的方式来set属性,但它肯定是可读的。

您需要先访问处理底层爪哇的对象,然后调用该查询属性的方法:

h = plot([0 1]) ;  %// This return the MATLAB handle of the lineseries 
hl = java(handle(h)) ; %// this return the JAVA handle of the lineseries 
allowedstyles = hl.getMarkerFaceColor.getAllowedStyles ; %// this return your property :) 

请注意,该属性实际上是一个整数索引。您的inspect窗口将其翻译为字符串[none,auto],而在我的配置中,即使检查窗口仅显示1

如果你想比一个其他价值的精确字符串翻译,你只能调用父类的方法:

hl.getMarkerFaceColor 

这将在你的控制台窗口的纯文本显示允许的风格。

ans = 
[email protected][style=none,allowedStyles=[none, auto],red=0.0,green=0.0,blue=0.0,alpha=0.0] 

如果你坚持progamatically获取此属性为一个字符串,那么你可以翻译上面使用toString方法。

S = char(hl.getMarkerFaceColor.toString) 
S = 
[email protected][style=none,allowedStyles=[none, auto],red=0.0,green=0.0,blue=0.0,alpha=0.0] 

然后解析结果。

+0

这非常有帮助。我觉得我简化了获取字符串的过程,通过执行以下操作:'aux = h1.getMarkerFaceColor.getAllowedStyles;' 'str = aux.toString;' – Humberto77 2014-10-02 19:32:18

+0

很高兴我能提供帮助。对我来说'h1.getMarkerFaceColor.getAllowedStyles'只返回一个标量值,所以我不能将它翻译成一个有意义的字符串。唯一的方法是解析父方法结果的字符串。 – Hoki 2014-10-02 20:01:29

+0

谢谢@Hoki我不知道java处理这很好。 +1 – 2014-10-02 22:22:18