How to count three pair of numbers in given matrix?

1 visualización (últimos 30 días)
Sushil Pokharel
Sushil Pokharel el 19 de Jul. de 2022
Respondida: Rik el 19 de Jul. de 2022
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.

Respuestas (1)

Rik
Rik el 19 de Jul. de 2022
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.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by