我的以下代码出现错误: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
最佳答案
我假设代码是为灰度图像设计的。对于二维以上的矩阵,您必须使用 permute
。一种解决方案可能是:
[irow icol d]=size(img);
temp=reshape(permute(img,[2,1,3]),[irow*icol,d]);
这会产生一个 nx3 矩阵,每一列对应一种颜色。您还必须更改最后一行,但我不知道您在期待什么。也许看看 cat
关于matlab - 在未定义 ND 数组上使用“转置”时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22576310/