2015-08-15 96 views
0

我想繪製錯誤信號。當錯誤爲零時,繪圖應爲黑色。每當出現錯誤時,它應該是紅色的。我在數組excdIdx中捕獲錯誤的索引。 我的目標是繪製紅色和非黑色誤差指數的誤差指數。出於某種原因,for循環無法正常工作。使用matlab繪製不同顏色的選定索引

ErrAxis是軸 excdIdx包含索引的表要繪製內部重定向

h(8) = subplot(plotCount,1,ErrAxis); 
    hold off; 
    if excdIdx > 0 

     plot(time(1:excdIdx),Output(1:excdIdx) - trueSignal(1:excdIdx),'k-'); hold on; 

     %this method to plot the error indices in red is not working 
     % for elem = 1: size(excdIdx, 2) 
     %  index_1 = excdIdx(elem); 
     %  index_2 = excdIdx(elem+1); 
     %  plot(time(index_1:index_1+1),Output(index_1:index_1+1) - trueSignal(index_1:index_1+1),'r-'); hold on; 
     % end 

    else 
     plot(time,Output - trueSignal,'k-'); hold on; 
    end 
+1

您可以創建一個[MCVE](http://stackoverflow.com/help/mcve)。 – Matt

回答

0

如果用戶要打印單個數據點,我認爲你應該使用scatter。請嘗試以下代碼:

h(8) = subplot(plotCount,1,ErrAxis); 
hold off; 
if excdIdx > 0 
    scatter(time(1:excdIdx),Output(1:excdIdx) - trueSignal(1:excdIdx),'markerfacecolor','k'); hold on; 
    for elem = 1: size(excdIdx, 2) 
     index_1 = excdIdx(elem); 
     index_2 = excdIdx(elem+1); 
     scatter(time(index_1:index_1+1),Output(index_1:index_1+1) - trueSignal(index_1:index_1+1),'markerfacecolor','r'); 
    end 
else 
    scatter(time,Output - trueSignal,'markerfacecolor','k'); hold on; 
end