How to extract column and row index and the corresponding value from a matrix?
조회 수: 7 (최근 30일)
이전 댓글 표시
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
답변 (2개)
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
2019년 6월 23일
편집: KALYAN ACHARJYA
2019년 6월 23일
@Madhan I tried, could not implement it without loop. +1
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!