2016-11-30 10 views
0
function res = plot2features(tset, f1, f2) 
% Plots tset samples on a 2-dimensional diagram 
% using features f1 and f2 
% tset - training set; the first column contains class label 
% f1 - index of the first feature (mapped to horizontal axis) 
% f2 - index of the second feature (mapped to vertical axis) 
% 
% res - matrix containing values of f1 and f2 features 

    % plotting parameters for different classes 
    % restriction to 8 classes seems reasonable 
    pattern(1,:) = 'ks'; 
    pattern(2,:) = 'rd'; 
    pattern(3,:) = 'mv'; 
    pattern(4,:) = 'b^'; 
    pattern(5,:) = 'gs'; 
    pattern(6,:) = 'md'; 
    pattern(7,:) = 'mv'; 
    pattern(8,:) = 'g^'; 

    res = tset(:, [f1, f2]); 

    % extraction of all unique labels used in tset 
    labels = unique(tset(:,1)); 

    % create diagram and switch to content preserving mode 
    figure; 
    hold on; 
    for i=1:size(labels,1) 
     idx = tset(:,1) == labels(i); 
     plot(res(idx,1), res(idx,2), pattern(i,:)); 
    end 
    hold off; 
end 

私はこの関数を書いており、plot2featutes()をMATLABの1つのウィジェットに表示したいとします。matlabの1つのウィンドウに複数のプロットを表示するにはどうすればいいですか?

私は、

動作しません
subplot(2,2,1);plot2features(train, 2, 3); 
subplot(2,2,2);plot2features(train, 2, 3); 
subplot(2,2,3);plot2features(train, 2, 3); 
subplot(2,2,4);plot2features(train, 2, 3); 

を以下を試してみました。

+1

それは動作しません。新しい図形 – matlabgui

+2

注記は 'plot2features'の中に新しい' figure'を作成します。それを修正して、軸ハンドルを入力として取り、それをplotコマンドの '' Parent''引数として与えます。 – mikkola

答えて

1

コメントに記載されているように、問題は関数内のfigure;行にあります。引数がなければ、figureは新しいFigureを作成し、そのFigureにフォーカスを切り替えます。あなたの関数は、より次のようになります。私はfigureを削除し、新しい軸となるよう最初のパスでhold offをオンテストに置き換え

  • function res = plot2features(tset, f1, f2) 
    % Plots tset samples on a 2-dimensional diagram 
    % using features f1 and f2 
    % tset - training set; the first column contains class label 
    % f1 - index of the first feature (mapped to horizontal axis) 
    % f2 - index of the second feature (mapped to vertical axis) 
    % 
    % res - matrix containing values of f1 and f2 features 
    
        % plotting parameters for different classes 
        % restriction to 8 classes seems reasonable 
        pattern = {'ks'; 'rd'; 'mv'; 'b^'; 'gs'; 'md'; 'mv'; 'g^'}; 
    
        res = tset(:, [f1, f2]); 
    
        % extraction of all unique labels used in tset 
        labels = unique(tset(:,1)); 
    
        % create diagram and switch to content preserving mode 
        for ii = 1:size(labels,1) 
         if ii == 1 
          hold off 
         else 
          hold on 
         end 
         idx = tset(:,1) == labels(ii); 
         plot(res(idx,1), res(idx,2), pattern{ii}); 
        end 
        hold off; 
    end 
    

    を私はあなたのコードに3つの変更を行いましたそれらの軸の内側に次のプロットが描画されます。

  • 私は曖昧
  • を避けるために、内蔵のi(SQRT(-1)である)からiiにあなたのインデックスを変更し、私は私自身の個人的な美学以外の理由もなくセルアレイにpatternを変更しました。このよう

コール:あなたは、*驚き驚き*、新しいフィギュアを作成し、あなたの `plot2features`機能で新しいフィギュアを作成し、プロットがで行われるため、

figure 
subplot(2,2,1);plot2features(train, 2, 3); 
subplot(2,2,2);plot2features(train, 2, 3); 
subplot(2,2,3);plot2features(train, 2, 3); 
subplot(2,2,4);plot2features(train, 2, 3); 
関連する問題