For loop in imresize function

3 次查看(过去 30 天)
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
Geoff Hayes 2019-4-11
编辑:Geoff Hayes 2019-4-11
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 个评论
Pablo Molina Garcia
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by