How to count three pair of numbers in given matrix?

조회 수: 1 (최근 30일)
Sushil Pokharel
Sushil Pokharel 2022년 7월 19일
답변: Rik 2022년 7월 19일
Hi there,
I have a column matrix:
x = [2 2 1 1 1 1 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 2 2 1 1 1 2 2 2 2 1 1 2 1 1 2 1 1 1 2 1 1 2 1 1 1 1 2 2 1];
first I want to count a pairs like
1,1,1 = a (say)
1,1,2 = b (say)
1,2,1 = c (say)
1,2,2 = d (say)
2,1,1 = e (say)
2,1,2 = f (say)
2,2,1 = g (say)
2,2,2 = h (say)
I want to create a 4x2 matrix whose elements are as follows:
x_4x2 = [ a b;
c d;
e f;
g h ]
I am not sure how the counting is done.
Your help will be greatly appreciated.

답변 (1개)

Rik
Rik 2022년 7월 19일
A simple loop should already do the trick.
I can also come up with much more complex solutions. If you split your initial array with cell2mat and convert each element to char, you can use ismember with a lookup table.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by