Search code examples
arraysmatlabmatrixresolution

Matlab - increase resolution of pattern in array


I have stored pattern in array, which is 1xM size.

Pattern = [0,0,1,0,1,0,1,0,0]

When plotted, it is square 3x3 where 1s are highlited.

I would like to increase resolution 4 times. So my square is now 12x12.

I tried imresize but I failed. I was also thinking to create 12x12 matrix with zeros and somehow fill it based on my original array.

The best way is to show a picture. One the left side is what i have and on the right side is what i'd like to have.

enter image description here


Solution

  • Use repelem (introduced in R2015a):

    Pattern = [0,0,1,0,1,0,1,0,0];
    Pattern = reshape(Pattern, 3, 3);
    N = 4;
    Result = repelem(Pattern, N, N);
    

    Or simply use indexing as follows:

    Pattern = [0,0,1,0,1,0,1,0,0];
    Pattern = reshape(Pattern, 3, 3);
    N = 4;
    Result = Pattern(1/N:1/N:size(Pattern,1), 1/N:1/N:size(Pattern,2));