JAN
JAN

Reputation: 21855

Copy one matrix into another in Matlab

How can I copy one matrix into another without for loops ? is it even possible ?

This is a short code that does it with loops , how can I avoid loops here ?

% 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  

Upvotes: 4

Views: 18395

Answers (1)

bla
bla

Reputation: 26069

just do:

  newImg = middleImg;

If what you meant is to copy everything but the first row and col, then just:

 newImg = middleImg(2:end,2:end);

Upvotes: 11

Related Questions