Reputation: 4373
I would need to resize a matrix (without interpolation) in Matlab into different resolution. The image below will highlight what I want:
Is there any built-in function for this in Matlab? If there isn't, what would be a good way to achieve this result?
Please let me know if my question isn't clear enough. Thank you for any help =)
Upvotes: 1
Views: 1041
Reputation: 112679
A = [1 2; 3 4]; %// data
m = 3; %// row repetition factor
n = 3; %// column repetition factor
B = A(ceil(1/m:1/m:size(A,1)), ceil(1/n:1/n:size(A,1)))
Upvotes: 5
Reputation: 1390
there is a easy and fast way in form of the function kron()
>> kron( [1 2; 3 4], ones(1))
ans =
1 2
3 4
>> kron( [1 2; 3 4], ones(2))
ans =
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
>> kron( [1 2; 3 4], ones(3))
ans =
1 1 1 2 2 2
1 1 1 2 2 2
1 1 1 2 2 2
3 3 3 4 4 4
3 3 3 4 4 4
3 3 3 4 4 4
it is even possible to stretch/shrink dimensions
>> kron( [1 2; 3 4], ones(1,2))
ans =
1 1 2 2
3 3 4 4
Upvotes: 5