2014-10-02 76 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