2016-07-19 54 views
-5

這個問題是關於使用matlab對數據進行分箱。我有兩個數據集。在一個數據集中,我使用x(代表速度)和y(代表功率)值對數據進行分類,並計算平均標準差,邊沿和h值(請參閱代碼),藉助該計算我需要識別並傳遞傳入數據(這裏是代碼中的這個是newdata)到它們所屬的特定的bin(我已經準備好在這裏給出下面的代碼),。在下面的代碼中,newdata將包含與bin匹配的新數據集。請幫我在哪裏,我會犯錯或修改它,我收到以下錯誤:任何人都可以幫助我在我的matlab編程中犯錯誤嗎?

Error using > 
Matrix dimensions must agree. 
Error in Binning_Online (line 23) 
     newdatabin=find(newdata>binEdges,1,'last'); %this is the bin number where the new data goes in 

代碼:

x= load speed; 
y= load power; 
newdata= load new_speed; 
topEdge = 20; % upper limit 
botEdge = 5; % lower limit 
numBins = 40; % define number of bins 
[N,edges,bins] = histcounts(y_vector,numBins); 
Pow_means = []; speed_means = []; 
for n = 1:numBins; 
    Pow_means(n,1) = mean(x_vector(bins==n,1)); % for each bins mean value calculation. 
    speed_means(n,1) = mean(y_vector(bins==n,1)); % for each bins mean value calculation. 
    pow_std(n,1) = std(x_vector(bins==n,1));  % for Standard deviation calculation 
    binEdges = linspace(botEdge, topEdge, numBins+1); 

    newdatabin= find(newdata>binedges,1,'last'); %this is the bin number where the new data goes in 
    h(newdatabin)=h(newdatabin)+1; 

end 
+0

什麼問題? – user4759923

+1

你爲什麼不寫錯誤信息? – giosans

+0

@giosans這是我得到的錯誤:錯誤使用> 矩陣尺寸必須一致。 Binning_Online錯誤(第23行) newdatabin = find(newdata> binEdges,1,'last'); %這是新數據進入的bin號碼 –

回答

1

正如其他人在評論中所指出的那樣,錯誤只是說, newdata是不同sizebinedges,因此執行newdata > binedges產生一個錯誤。

我的猜測是,線

binEdges = linspace(botEdge, topEdge, numBins+1) 

應該

binEdges = linspace(botEdge, topEdge, numBins) 

上,你newdata數組的長度爲numBins

的假設,如果假設是錯誤的,那麼你的問題是您正在任意設定與newdata的長度不符的箱數。 而不是使用幻數你應該從你的數據中獲得你的數字。 (即代替numbins = 40也許你應該在做numbins = length(newdata)

相關問題