How to extract column and row index and the corresponding value from a matrix?

7 ビュー (過去 30 日間)
Noxi
Noxi 2019 年 6 月 23 日
コメント済み: Andrei Bobrov 2019 年 6 月 26 日
I have a huge matrix of pixel values from an image converted into a text file. I need to convert this matrix into a table with column index, row index and the element as seperate columns of the table. How do I do this?
I'm doing this to figure out of the Centre of mass of a 2D projection of an object in the image. The image is a binary image with a single object in white and the background in black. Is there any other way to do this?
  2 件のコメント
madhan ravi
madhan ravi 2019 年 6 月 23 日
A sample illustration would help
Noxi
Noxi 2019 年 6 月 23 日
Like this:
from -
0 1 4
7 6 0
to -
row column element
1 1 0
1 2 1
1 3 4
2 1 7
2 2 6
2 3 0

サインインしてコメントする。

回答 (2 件)

madhan ravi
madhan ravi 2019 年 6 月 23 日
編集済み: madhan ravi 2019 年 6 月 23 日
m = [0 1 4
7 6 0];
[Rows,Columns] = ind2sub(size(m),(1:numel(m))');
Wanted = [Rows,Columns,m(:)];
Wantedtable = sortrows(array2table(Wanted,'VariableNames',{'Rows','Columns','Elements'}),1)
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 23 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 23 日
@Madhan I tried, could not implement it without loop. +1

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2019 年 6 月 23 日
A = [0 1 4
7 6 0];
out = sortrows([fullfact(size(A)),A(:)]);
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 24 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 24 日
It's great!
Andrei Bobrov
Andrei Bobrov 2019 年 6 月 26 日
Thank you Kalyan!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by