2015-12-21 192 views
0

我有一個簡單的問題: 我有一個向量testv昏暗。 (1000X784)。我想將它的一些行(錯誤分類的成員)轉換爲dim模型。 (28X28)。我做到以下幾點:如何在MATLAB中將陣列向量轉換爲矩陣

x = zeros(28,28); 
    idx = find(labtrain ~= labtest); % the index of the misclassified members. 
    for k = 1:length(idx) % plot the misclassified members 
     x(:) = testv(idx,:); 
     figure 
     image(x) 
     end 

,但我得到了以下錯誤:

In an assignment A(:) = B, the number of elements in A and B must be the same. 

我無法弄清楚如何擺脫這一點。
任何幫助表示讚賞。

回答

0

你試過「reshape」嗎?

重塑一個1乘10載體導入5×2矩陣:

A = 1:10; 
B = reshape(A,[5,2]) 

B = 

1  6 
2  7 
3  8 
4  9 
5 10 
+0

我嘗試以下:' X =零(28,28); idx = find(labtrain〜= labtest);對於k = 1:長度(idx) x =重塑(testv(idx,:),[28,28]); 圖 圖像(X) end'這一次,我得到這個錯誤:'使用錯誤重塑 重塑元素的數量不得change.' – KianStar

+0

太奇怪了,因爲當我嘗試在以下命令行:'X = reshape(testv(9,:),[28,28]);'它很好。 – KianStar

+0

我的IDX向量是'[9 12.00 36.00 40.00 51.00 68.00 80.00 84.00 105.00 106.00 183.00]' – KianStar