Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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  
like image 689
JAN Avatar asked Dec 20 '22 11:12

JAN


1 Answers

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);
like image 145
bla Avatar answered Jan 03 '23 07:01

bla