Search code examples
matlabdictionarypixel

Mapping pixels of two matrices


Say that I have two matrices of the following sizes:

matrix_1 = 30090x2

matrix_2 = 170x177

Assume here that the number of rows n matrix_1 represents the number of pixels. You can see that the size of matrix_2 is equal to the number of pixels.

What I'm trying to do is map the pixels in matrix_1 to the pixels in matrix_2, such that for example:

matrix_1(1) = matrix_2(1)
matrix_1(2) = matrix_2(2)
matrix_1(3) = matrix_2(3)
......
......
matrix_1(n) = matrix_2(n)

How can I do that in matlab?


Solution

  • Here is an option

      matrix_1 = matrix_2(:);
    

    which copies the elements (all of them) of matrix_2 in one long column.

    In your data you said that matrix_1 has two columns, you can add a further empty column by doing, for instance

      matrix_1  = [matrix_1 zeros(size(matrix_1))];