2011-04-08 59 views
2

我是一名本科生,在做我最後的matlab項目,我必須設置許多當前打開的圖形對象的位置。我無法單獨調用它們,也不能通過使用索引並將它們放入循環來調用所有的手柄。有沒有辦法通過一個或兩個命令來設置多個圖形對象的位置或可以執行此操作的函數?通過單個命令設置matlab中許多圖形對象的位置

回答

4

SET函數允許您輸入圖形句柄的矢量以對單元陣列,結構和屬性/值對的組合進行操作,以便您可以修改屬性名稱和值的多個屬性一個函數調用。

例如,假設您已經創建了4套軸的所有在另一個頂部堆疊:

hAxes1 = axes(); 
title('Axes 1'); 
hAxes2 = axes(); 
title('Axes 2'); 
hAxes3 = axes(); 
title('Axes 3'); 
hAxes4 = axes(); 
title('Axes 4'); 

您可以爲每個組軸的一個新的位置調用一次SET爲如下:

hVector = [hAxes1; hAxes2; hAxes3; hAxes4]; %# Vector of graphics handles 
propertyCell = {'Position'};   %# Cell array containing the property name 
valueCell = {[0.1 0.6 0.3 0.3]; ... %# 4-by-1 cell array containing the new 
      [0.6 0.6 0.3 0.3]; ... %# values for the axes positions 
      [0.1 0.1 0.3 0.3]; ... 
      [0.6 0.1 0.3 0.3]}; 
set(hVector,propertyCell,valueCell); %# Set the new positions 

你應該在你的身材窗口中看到這一點:

enter image description here