For loop in imresize function

4 vues (au cours des 30 derniers jours)
Pablo Molina Garcia
Pablo Molina Garcia le 11 Avr 2019
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

Réponse acceptée

Geoff Hayes
Geoff Hayes le 11 Avr 2019
Modifié(e) : Geoff Hayes le 11 Avr 2019
Pablo - why are you doing this row by row? Why not just resize the matrix as
A_101 = imresize(A, [10,101]);
For your code
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 commentaire
Pablo Molina Garcia
Pablo Molina Garcia le 15 Avr 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by