2013-02-03 97 views
0

我有一個函數ParallelPlot如下所示:錯誤的ploting在GUI軸

function ParallelPlot(hAxes, normalizedMatrix) 
%//PARALLELPLOT Do Parallel Coordinates Plot for a normalized matrix 
%//columns 

%// Input:- 
%// o hAxes: Handle to an axes. 
%// o normalizedMatrix : n-by-m normalized matrix 

DEFAULT_AXES_COLOR = [0 0 0]; 

[MATRIX_HEIGHT MATRIX_WIDTH] = size(normalizedMatrix); 
ALL_PLOTS_MATRIX    = zeros(MATRIX_HEIGHT,MATRIX_WIDTH); 


DEFAULT_MARKER_EDGE_COLOR = [.2 .3 .4]; 
DEFAULT_MARKER_FACE_COLOR = [.3 .7 .2]; 
DEFAULT_MARKER_SHAPE  = 's'; 
DEFAULT_MARKER_SIZE  = 10; 
DEFAULT_MARKER_COLOR  = [1 0 0]; 
DEFAULT_MARKER_LINE_STYLE = '-'; 
DEFAULT_MARKER_LINE_WIDTH = 1; 

SELECTED_MARKER_EDGE_COLOR = [.5 .5 .8]; 
SELECTED_MARKER_FACE_COLOR = [.4 .4 .6]; 
SELECTED_MARKER_SHAPE  = 'x'; 
SELECTED_MARKER_SIZE  = 15; 
SELECTED_MARKER_COLOR  = [1 1 1]; 
SELECTED_MARKER_LINE_STYLE = '--'; 
SELECTED_MARKER_LINE_WIDTH = 4; 

InitializeAllPlotsMatrix; 
set(hAxes, 'color', DEFAULT_AXES_COLOR); 
set(hAxes,'xLim',[0 MATRIX_WIDTH+1]); 

    function plotHandle = InitializeNewPlot 
     plotHandle = plot(hAxes   , NaN,NaN      ); 
     set(plotHandle, 'Marker'   , DEFAULT_MARKER_SHAPE   ); 
     set(plotHandle, 'MarkerEdgeColor' , DEFAULT_MARKER_EDGE_COLOR  ); 
     set(plotHandle, 'MarkerFaceColor' , DEFAULT_MARKER_FACE_COLOR  ); 
     set(plotHandle, 'MarkerSize'  , DEFAULT_MARKER_SIZE   ); 
     set(plotHandle, 'LineStyle'  , DEFAULT_MARKER_LINE_STYLE  ); 
     set(plotHandle, 'LineWidth'  , DEFAULT_MARKER_LINE_WIDTH  ); 
     set(plotHandle, 'Color'   , DEFAULT_MARKER_COLOR   ); 
     set(plotHandle, 'ButtonDownFcn' , @ParallelPlotButtonDownCallback); 
    end 

    function InitializeAllPlotsMatrix 
     for i = 1 : MATRIX_HEIGHT 
      for j = 1 : MATRIX_WIDTH         
       plotHandle = InitializeNewPlot; 
       hold on; 
       if j <= MATRIX_WIDTH - 1 
        xDataValue = [ j j+1]; 
       else 
        xDataValue = j; 
       end 
       if j <= MATRIX_WIDTH - 1 
        yDataValue = [ normalizedMatrix(i,j) , normalizedMatrix(i,j+1)]; 
       else 
        yDataValue = normalizedMatrix(i,j); 
       end 

       set(plotHandle,'xData', xDataValue,'yData', yDataValue); 

       ALL_PLOTS_MATRIX(i,j) = plotHandle; 
      end 
     end 
    end 

    function ParallelPlotButtonDownCallback(plotHandle,eventHandle) %#ok<INUSD> 

     [i, j] = find(ALL_PLOTS_MATRIX == plotHandle); %#ok<NASGU> 

     set(ALL_PLOTS_MATRIX, 'Marker'    , DEFAULT_MARKER_SHAPE  ); 
     set(ALL_PLOTS_MATRIX, 'MarkerEdgeColor'  , DEFAULT_MARKER_EDGE_COLOR ); 
     set(ALL_PLOTS_MATRIX, 'MarkerFaceColor'  , DEFAULT_MARKER_FACE_COLOR ); 
     set(ALL_PLOTS_MATRIX, 'MarkerSize'   , DEFAULT_MARKER_SIZE  ); 
     set(ALL_PLOTS_MATRIX, 'LineStyle'   , DEFAULT_MARKER_LINE_STYLE ); 
     set(ALL_PLOTS_MATRIX, 'LineWidth'   , DEFAULT_MARKER_LINE_WIDTH ); 
     set(ALL_PLOTS_MATRIX, 'Color'    , DEFAULT_MARKER_COLOR  ); 

     relevantPlotsHandles = ALL_PLOTS_MATRIX(i,:); 
     set(relevantPlotsHandles, 'Marker'   , SELECTED_MARKER_SHAPE  ); 
     set(relevantPlotsHandles, 'MarkerEdgeColor' , SELECTED_MARKER_EDGE_COLOR); 
     set(relevantPlotsHandles, 'MarkerFaceColor' , SELECTED_MARKER_FACE_COLOR); 
     set(relevantPlotsHandles, 'MarkerSize'  , SELECTED_MARKER_SIZE  ); 
     set(relevantPlotsHandles, 'LineStyle'  , SELECTED_MARKER_LINE_STYLE); 
     set(relevantPlotsHandles, 'LineWidth'  , SELECTED_MARKER_LINE_WIDTH); 
     set(relevantPlotsHandles, 'Color'   , SELECTED_MARKER_COLOR  ); 
    end 
end 

當我使用該功能類似axes()空軸,它工作正常,但如果我用我的任何GUI的使用軸,它拋出異常它的行:

plotHandle = plot(hAxes , NaN,NaN); 

和錯誤是:

??? Error using ==> set 
Invalid handle object. 

Error in ==> newplot at 66 
set(fig,'nextplot','add'); 

Error in ==> ParallelPlot>InitializeNewPlot at 37 
     plotHandle = plot(hAxes   , NaN,NaN      ); 

Error in ==> ParallelPlot>InitializeAllPlotsMatrix at 51 
       plotHandle = InitializeNewPlot; 

Error in ==> ParallelPlot at 32 
InitializeAllPlotsMatrix; 

我不知道爲什麼會發生這種錯誤,任何人都知道如何解決這個問題?

回答

0

解決方法是將GUI屬性nextplot設置爲add

enter image description here

但錯誤會再次爲未來的地塊被拋出!