我的以下代码收到错误: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
答案 0 :(得分:2)
我假设代码是为灰度图像设计的。对于具有两个以上维度的矩阵,您必须使用permute
。一种解决方案可能是:
[irow icol d]=size(img);
temp=reshape(permute(img,[2,1,3]),[irow*icol,d]);
这导致nx3矩阵,每列对应一种颜色。你也必须改变最后一行,但我不知道你的期望。也许看看cat