How to count three pair of numbers in given matrix?

1 visualizzazione (ultimi 30 giorni)
Sushil Pokharel
Sushil Pokharel il 19 Lug 2022
Risposto: Rik il 19 Lug 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.

Risposte (1)

Rik
Rik il 19 Lug 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.

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Tag

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by