How to count three pair of numbers in given matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Rik
am 19 Jul. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!