MATLAB Answers

How to count repeated number pairs in matlab?

15 ビュー (過去 30 日間)
Ram k
Ram k 2016 年 5 月 5 日
コメント済み: Image Analyst 2016 年 5 月 5 日
Suppose I have a sequence 5,5,5,1,5,4,1,2,3,5,5,1,5 then 5 followed by 5 is 3 so answer is 3, so how to programme it in Matlab.

  0 件のコメント

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

回答 (2 件)

CS Researcher
CS Researcher 2016 年 5 月 5 日
編集済み: CS Researcher 2016 年 5 月 5 日
Lets assume the vector is a, i.e.,
a = [5,5,5,1,5,4,1,2,3,5,5,1,5];
Try this:
numberOfPairs = sum(numel(find(diff(a)==0)));
Hope this helps!

  1 件のコメント

Ram k
Ram k 2016 年 5 月 5 日
I want to obtain transition probability matrix by this sequence in that I want calculate probability matrix by equation as follows probability= (number of pairs one state followed by other)/(number of pairs first state followed by any another state), how to do this.

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


Image Analyst
Image Analyst 2016 年 5 月 5 日
You can find out how many pairs of all integers are next to all other integers with the gray level cooccurrence matrix, given by graycomatrix() if you have the Image Processing Toolbox
m = [5,5,5,1,5,4,1,2,3,5,5,1,5]
glcm = graycomatrix(m, 'NumLevels', max(m),'GrayLimits',[])
glcm =
0 1 0 0 2
0 0 1 0 0
0 0 0 0 1
1 0 0 0 0
2 0 0 1 3
For example, 5 is next to 5 3 times. 5 is next to 1 two times. 3 is next to 2 two times, etc.

  2 件のコメント

Ram k
Ram k 2016 年 5 月 5 日
I want to obtain transition probability matrix by this sequence in that I want calculate probability matrix by equation as follows probability= (number of pairs one state followed by other)/(number of pairs first state followed by any another state), how to do this.
Image Analyst
Image Analyst 2016 年 5 月 5 日
To get "(number of pairs one state followed by other)" - read it from the GLCM array. To get "(number of pairs first state followed by any another state)" just count up the total number of that number as long as that number is not in the last row or last column
subArray = fullMatrix(1:end-1, 1:end-1);
numAnyPairs = sum(subArray(:));

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

Community Treasure Hunt

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

Start Hunting!

Translated by