hi every body !! my question is how to get the position of the similar elements in same matrix??

suppose if i have matrix
M=[0 0 0 0 0;0 0 -1 0 0; 0 0 -1 0 -1;0 0 -1 0 -1; -1 -1 0 -1 -1];
i have to compare each row as in..1st row to 2nd row then 1st row to third row, 1st row to 4th one and 1st to 5th one and then again 2nd row to 3rd ans so on....I m trying to compare first and 2nd row row where
ft=[0 0 0 0 0];
st=[0 0 -1 0 0];
now i want that output should be pos=1,2,4,5. Where 1,2,4,,5 are the position of the similar elemnts in ft and st. I have tried many ways but -1 is the barrier here.
M stuck here plz help me out of this...any kind of help will b appreciated. my email id:- titre.rutika25@gmail.com

 채택된 답변

dpb
dpb 2015년 10월 27일
편집: dpb 2015년 10월 27일
Basic idea is
>> find(M(1,:)==M(2,:))
ans =
1 2 4 5
>>
Apply above for each row pairwise; note you'll have to save results in a cell array as there won't necessarily be the same length output vector for each row (and could, theoretically, have an empty row as well).
Implementation is a nested loop;
R=size(M,1); % # rows
k=0; % output counter
for i=1:R
for j=i+1:R
k=k+1;
out{k}=find(M(j,:)==M(i,:));
end
end

추가 답변 (3개)

What does similar mean to you? Is 3.0001 similar to 3.0004? Or do you mean equal rather than similar? And, if you mean equal, are you using integers, or floating point numbers with fractional parts? Why? See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
And why not just use a for loop:
[rows, columns] = size(M)
for row = 1 : rows
thisRow = M(row, :);
newM = repmat(thisRow, [rows, 1]);
differences = M - newM;
% etc.
end
Rutika Titre
Rutika Titre 2015년 10월 29일
Thank u all, I really appreciate that you all tuk time to help me out vth this.I am a novice to MATLAB. Thank u so much
Rutika Titre
Rutika Titre 2015년 10월 29일
hey !!! Again a query.....I have been searching on Progressive Edge Growth algorithm. My project is on this algorithm. According to my search many have worked on it, but they all have given pseudo codes in many paper. After understanding the algorithm, I have sumhow managed to start writing the code as I was not getting anything proper for that algorithm. If anybody can help me with good website or any paper for PEG algorithm.I have read many papers on it.Plz help me out here.

댓글 수: 1

VIrtually all the Image Processing articles are logged here: http://www.visionbib.com/bibliography/contents.html There is a search capability at the bottom of the page. Good luck.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 10월 27일

댓글:

2015년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by