For loop in imresize function
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pablo Molina Garcia
il 11 Apr 2019
Commentato: Pablo Molina Garcia
il 15 Apr 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
0 Commenti
Risposta accettata
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.
Più risposte (0)
Vedere anche
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!