creating a matrix from an image

1 view (last 30 days)
Shabnam M
Shabnam M on 11 Dec 2020
Edited: Rik on 11 Dec 2020
Dear all,
I have an image and when it is read in matlab, it is [m*n] matrix, named M,
I need to create another matrix, named MM, which is exactly M, but the indexes are also listed in that.
In fact, MM has 3 columns and the third column is M (:), but the first two columns are i and j which
i=1:m, j=1:n
Thanks in advance
  2 Comments
Shabnam M
Shabnam M on 11 Dec 2020
I need also the index related to data of MM

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 11 Dec 2020
Edited: Ameer Hamza on 11 Dec 2020
You can use meshgrid() like this
[r,c] = ndgrid(1:size(M,1), 1:size(M,2));
MM = [r(:), c(:), M(:)];
  6 Comments
Ameer Hamza
Ameer Hamza on 11 Dec 2020
Yes, ndgrid is more appropriate here. I have edited the answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by