## For loop in imresize function

Asked by Pablo Molina Garcia

### Pablo Molina Garcia (view profile)

on 11 Apr 2019
Latest activity Commented on by Pablo Molina Garcia

### Pablo Molina Garcia (view profile)

on 15 Apr 2019
Accepted Answer by Geoff Hayes

### Geoff Hayes (view profile)

My current matrix A has 10x801 and the idea is to get a final resized matrix (A_101) of 10x101. I use imresize in one row and it worked well, and now I want to run a for loop in the rest of rows. Here is a script attempt. The issue that pops up is "Unable to perform assignment because the left and right sides have a different number of elements". Any help is appreciated. Thanks!
for i=1:10;
A_101(i) = imresize(A(1,:), [i,101]);
end

### Geoff Hayes (view profile)

Answer by Geoff Hayes

### Geoff Hayes (view profile)

on 11 Apr 2019
Edited by Geoff Hayes

### Geoff Hayes (view profile)

on 11 Apr 2019

Pablo - why are you doing this row by row? Why not just resize the matrix as
A_101 = imresize(A, [10,101]);
for i=1:10;
A_101(i) = imresize(A(1,:), [i,101]);
end
if you really wanted to do this row by row, then you would need to adjust where the i or row number is being used in the code. Also, you need to realize that you are assigning a row (from the imresize output) to perhaps a single value in your matrix. Instead try
A_101 = zeros(10,101);
for k=1:10;
A_101(k,:) = imresize(A(k,:), [1,101]);
end
Note how k is used (instead of i) and how we pre-size the A_101 array, assigning a row (which is a resized kth row of A) to it on each iteration of the loop. But I would recommend against this approach unless there is some requirement to do the resizing row by row.

#### 1 Comment

Pablo Molina Garcia

### Pablo Molina Garcia (view profile)

on 15 Apr 2019
Thank you very much Geoff! I did't know that you could resize the whole matrix. As you suggested, I have used the first option, but anywhere, both of them worked perfectly.