How to count three pair of numbers in given matrix?

2 次查看(过去 30 天)
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