以下MATLAB代码有什么问题?

时间:2013-09-13 05:50:08

标签: image matlab image-processing

这是删除矩阵中的某些元素。我想要1:hseam和hseam:结束。

for i=1:3                                                                  
    for j=1:cols                                                           
        if hseam(j)==1
            Img(:,j,i)=[im(2:rows,j,i)]; 
        elseif hseam(j)==rows
            Img(:,j,i)=[im(1:rows-1,j,i)];
        else            
            Img(:,j,i)=[im((1:hseam(j)-1),j,i) im((hseam(j)+1:end),j,i)];
        end
    end
end

这是我得到的错误:

???使用==>时出错horzcat CAT参数维度不一致。

==>中的错误在17点减少高度             Img(:,j,i)= [im((1:hseam(j)-1),j,i)im((hseam(j)+1:end),j,i)];

1 个答案:

答案 0 :(得分:1)

假设您要提取 1:hseam和hseam:end(不完全确定我理解您的代码的完整意图),您也可以这样做:

Img = im([1:hseam, heasm:end],:,:)

不需要在这里循环......