Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在没有 for 循环的情况下将一个矩阵复制到另一个矩阵?有可能吗?
这是一个使用循环的短代码,我怎样才能在这里避免循环?
% middleImg , newImg are matrices [rows columns] = size(middleImg); for i=1:rows for j=1:columns newImg(i,j) = middleImg(i+1,j+1); end end
做就是了:
newImg = middleImg;
如果您的意思是复制除第一行和列之外的所有内容,那么只需:
newImg = middleImg(2:end,2:end);