3

我的以下代码出现错误:temp=reshape(img',irow*icol,1);

   Error message:Error using  ' 
   Transpose on ND array is not defined.

这个有什么解决办法。我想我必须使用 permute(A,order) 命令。但我不知道如何在我的代码中使用这个命令。你知道有什么解决办法吗?

 for i=1:M
str=strcat(int2str(i),'.jpg');   %concatenates two strings that form the name of the image
eval('img=imread(str);');
subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
imshow(img)
if i==3
    title('Training set','fontsize',18)
end
drawnow;
[irow icol]=size(img);    % get the number of rows (N1) and columns (N2)
temp=reshape(img',irow*icol,1);     %creates a (N1*N2)x1 matrix
S=[S temp];         %X is a N1*N2xM matrix after finishing the sequence
                    %this is our S
end
4

1 回答 1

2

我假设代码是为灰度图像设计的。对于多于二维的矩阵,您必须使用permute. 一种解决方案可能是:

[irow icol d]=size(img);
temp=reshape(permute(img,[2,1,3]),[irow*icol,d]);

这会产生一个 nx3 矩阵,每列对应一种颜色。您还必须更改最后一行,但我不知道您在期待什么。也许看看cat

于 2014-03-22T10:53:54.280 回答