For loop in imresize function

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Geoff Hayes
Geoff Hayes il 11 Apr 2019
Modificato: Geoff Hayes il 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 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 Commento
Pablo Molina Garcia
Pablo Molina Garcia il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by