matlab - 在未定义 ND 数组上使用“转置”时出错?

标签 matlab matrix transpose permute

我的以下代码出现错误: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/

相关文章:

matlab - 为 NaN 值创建 Bin

language-agnostic - 不同语言在机器学习中的相对受欢迎程度?

sql - 在 SQL 中查询一个杂乱的表

python - 是否有内置的 python 来从多个列表创建元组?

matlab - 从变量创建向量范围

python - 将多个文本文件中具有一定行数的一列数据拉入一个文本文件

MATLAB - 直接将标称数据转换为数值

python - 非常基本的 Numpy 数组维度可视化

python - 如何从 python 2.7 中的三个列表创建矩阵列表?

python - 转置 csv 同时保留 ID