2016-11-13 61 views
0

這是什麼錯誤?什麼是指數超過了matlab中的矩陣尺寸誤差?

索引超出矩陣的尺寸。
評估錯誤(第5行)
binTempX(i,[1,2,3,4,5,6,7,8])= parentXY(i,[1,2,3,4,5,6 ,7,8]);

function [tempX_Y_FXY] = evalution(parentXY,fXY) 

for i=1:6 

    binTempX(i,[1,2,3,4,5,6,7,8])=parentXY(i,[1,2,3,4,5,6,7,8]); 

    binTempY(i,[9,10,11,12,13,14,15,16],8)=parentXY(i,[9,10,11,12,13,14,15,16]); 

    decTempX=bin2dec(binTempX(i,[1,2,3,4,5,6,7,8])); 
    decTempY=bin2dec(binTempY(i,[9,10,11,12,13,14,15,16])); 

    tempX_Y_FXY(i,1)=decTempX; 
    tempX_Y_FXY(i,2)=decTempY; 

    tempX_Y_FXY(i,3)=fXY(decTempX,decTempY); 

end 

tempX_Y_FXY=sortrows(tempX_Y_FXY,3); 


end 
+0

該錯誤非常具有描述性。它說你用於'binTempX'或'parentXY'的索引超過了那個矩陣的維數。所以你可能應該檢查這兩個變量,並確保它們是你期望它們在你的代碼中的大小。另外,請在您的問題中正確地格式化代碼。所有你需要做的就是選擇它並點擊'ctrl-k'。 – beaker

回答

0
binTempX(i,[1,2,3,4,5,6,7,8])=parentXY(i,[1,2,3,4,5,6,7,8]); 

%%% ------- what is this 8 doing here??? 
binTempY(i,[9,10,11,12,13,14,15,16],**8**)=parentXY(i,[9,10,11,12,13,14,15,16]); 

decTempX=bin2dec(binTempX(i,[1,2,3,4,5,6,7,8])); 
decTempY=bin2dec(binTempY(i,[9,10,11,12,13,14,15,16])); 

tempX_Y_FXY(i,1)=decTempX; 
tempX_Y_FXY(i,2)=decTempY; 

tempX_Y_FXY(i,3)=fXY(decTempX,decTempY); 

更改爲:

binTempX(i,1:8)=parentXY(i,1:8); 

% removed the 8, because I think it is typo?? 
binTempY(i,9:16)=parentXY(i,9:16); 

decTempX=bin2dec(binTempX(i,1:8)); 
decTempY=bin2dec(binTempY(i,9:16)); 

tempX_Y_FXY(i,1)=decTempX; 
tempX_Y_FXY(i,2)=decTempY; 

tempX_Y_FXY(i,3)=fXY(decTempX,decTempY); 
如果您想選擇/分配多個連續列

使用1:8的符號,例如。兩者都應該工作,但在我看來,第二個更清晰和更容易維護。

就像燒杯說的那樣,檢查你的矩陣的大小,你使用的矩陣是否至少有6行16列?

+0

如果這解決了您的錯誤,那麼投票就很好。 – Romano

相關問題