hi, i need to find the location of elements in a matrix as (row,column) value. what function is used to get the row and column of a element?

댓글 수: 2

Your title does not match the content of your question
sir, i need to find the row,column value for each element in a matrix

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 17일
편집: Azzi Abdelmalek 2013년 10월 17일
Use find function
doc find
Example
A=[1 2 3;4 5 6;7 8 9]
[ii,jj]=find(A)

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 10월 17일
A = [4 0 3 0
4 4 4 -3
-3 -3 2 -3
5 0 -1 5]
s = size(A);
[irow,icol] = ndgrid(1:s(1),1:s(2));
out = [irow(:),icol(:),A(:)];

댓글 수: 3

sheno39
sheno39 2013년 10월 18일
편집: Azzi Abdelmalek 2013년 10월 18일
I=[2 3 10 4 6; 1 4 7 5 3; 5 2 8 4 3;8 2 1 7 3;1 9 8 3 4;];
D = padarray(I,[1 1],0,'both');
[x y]=size(D);
m=1;
n=1;
for i=2:x-1
for j=2:y-1
A=[D(i-1,j-1:j+1),D(i,j-1),D(i,j+1),D(i+1,j-1:j+1)];
I1(m,n)=max(A(:));
%[maxval(m,n) index(m,n)]=max(A(:));
n=n+1;
end
m=m+1;
n=1;
end
[tc locatn]=ismember(I1,I);
s=[5,5];
[R C]=ind2sub(s,locatn');
Required output
locatn=[7 11 12 11 17;
3 11 11 11 21;
4 4 12 13 19;
10 10 10 13 19;
10 4 10 15 19]
i got the output as,
locatn=[7 11 12 11 3;
3 11 11 11 21;
4 4 12 4 12;
10 10 10 4 12;
10 4 10 4 12]
can u help me to get the required output? how to correct this code?
Can you explain, for example, why, for locatn(1,5) , it should be 17 and not 3

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 10월 17일

댓글:

2013년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by