Matrix 如何在MATLAB中将阵列向量转换为矩阵

Matrix 如何在MATLAB中将阵列向量转换为矩阵,matrix,vector,Matrix,Vector,我有一个简单的问题: 我有一个dim的向量testv(1000X784)。我想将它的一些行(错误分类的成员)转换为dim矩阵(28X28)。我做了以下工作: x = zeros(28,28); idx = find(labtrain ~= labtest); % the index of the misclassified members. for k = 1:length(idx) % plot the misclassified members x

我有一个简单的问题: 我有一个dim的向量
testv
<代码>(1000X784)。我想将它的一些行(错误分类的成员)转换为dim矩阵<代码>(28X28)。我做了以下工作:

    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.
我想不出如何摆脱它。
非常感谢您的帮助。

您试过“”吗

将1×10的向量重塑为5×2的矩阵:

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

B =

 1     6
 2     7
 3     8
 4     9
 5    10

我尝试了以下方法:`x=0(28,28);idx=查找(labtrain~=labtest);对于k=1:length(idx)x=重塑(testv(idx,:),[28,28]);figure image(x)end`这次我遇到了这个错误:
使用整形来整形元素的数量时出错,不能更改。
太奇怪了,因为当我在命令行中尝试以下操作时:
x=restrape(testv(9,:),[28,28])一切正常。我的idx向量是
[9 12.00 36.00 40.00 51.00 68.00 80.00 84.00 105.00 106.00 183.00]
也许你可以告诉其他人问题出在哪里,以防其他人需要知道。当然,我必须逐个组件选择idx组件,因为它是一个向量:x=重塑(testv(idx(k,1),:),[28,28]);