Count the number of times a value repeats between certain rows in a matrix.
조회 수: 3(최근 30일)
표시 이전 댓글
Hi all,....if i had a Matrix Ex...A(2,5,15,65,102
2,65,1,105,55
65,104,15,19,5).....so on.
how to find the total number of times a value repeats between Row1 and Row2....Ans 2,65
then Row2 and Row3....Ans 65.
then Row3 and 4......and so on..
Also inputting which rows i want to check.....maybe between row1 and row4 for example....then row2 and row5....and so on,would be very helpful
Thank you.
채택된 답변
Matt J
2022년 1월 19일
A=[2,5,15,65,102;
2,65,1,105,55;
65,104,15,19,5];
skip=1;
A1=A(1:end-skip,:); A2=A(skip+1:end,:);
M=size(A,2);
result=0;
for i=0:M-1
result=result+sum(A1==circshift(A2,[0,i]),2);
end
result
추가 답변(1개)
David Hill
2022년 1월 19일
A=[2,5,15,65,102;2,65,1,105,55;65,104,15,19,5];
i=A(1,ismember(A(1,:),A(2,:)));
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!