4

文字通りこれらの図を取得して、GUI の軸ウィンドウに配置するにはどうすればよいですか?

以下の例のユーザー定義コードのどこにハンドルを配置すればよいかわかりません。この例に似た合計 4 つの図があります。4 つの図を個別のウィンドウではなく GUI ウィンドウに表示したいので、.fig ファイルに 4 つの軸ウィンドウを作成しました。

この特定の図のコードは、値が 1 であるか 0 であるかに基づいて、66 個の白黒の四角形のグリッドを描画しますMyVariable。1 の場合は黒、0 の場合MyVariableは白ですMyVariable。.fig GUI のファイルがあります。 、GUI を制御するための 1 つのファイルと、GUI にリンクするユーザー定義コードを含む 1 つのファイル。

function test = MyScript(handles)

間にたくさんのコード

% Initialize and clear plot window 
figure(2); clf;

% Plot the west wall array panels depending on whether or not they are
% shaded or unshaded
for x = 1:11
     for y = 1:6
  if (MyVariable(x,y) == 1)
  rectangle('position', [x-1, y-1, 1, 1] ,'EdgeColor', 'w', 'facecolor', 'k')
  else if(MyVariable(x,y) == 0)
  rectangle('position', [x-1, y-1, 1, 1], 'facecolor', 'w')
end
end
end
end

title('West Wall Array',... 
  'FontWeight','bold')

axis off

上記のコードの図は次のようになります。 ここに画像の説明を入力

以前にスクリプトを個々の関数に分割しなかったため、関数定義には 4 つのプロットすべてのスクリプト コードがすべて含まれています。

私のGUIスクリプトコードには以下が含まれています:

   MyScript(handles);
4

2 に答える 2

2

Figure の 'CurrentAxes' プロパティを設定することにより、各プロット コマンドの前にプロットする軸を設定できます。

GUIDE 内では、特定の軸にタグを付けることができます (例: http://www.mathworks.com/help/matlab/creating_guis/gui-with-multiple-axes-guide.html ) 。次に、描画コード内で、「set」関数と「CurrentAxes」プロパティを使用して、プロットする軸を指定します。

簡単な例を以下に示しますが、GUIDE は使用せず、基本的なサブプロット軸ハンドルのみを使用しています。

% plots in most recent axis by default (ax2)
fig = figure;
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
plot(rand(1,10));

% indicate that you want to plot in ax1 instead
fig = figure;
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
set(gcf, 'CurrentAxes', ax1);
plot(rand(1,10));
于 2013-12-17T22:07:09.847 に答える