how to change 3d array to 2 d array

1 vue (au cours des 30 derniers jours)
satria dharma
satria dharma le 24 Jan 2021
i have table
A 1 N
B 1 J
C 1 N
A 2 J
B 2 N
C 2 J
I want change that table to
A B C
N 1 2 1
J 2 1 2

Réponse acceptée

Stephan
Stephan le 24 Jan 2021
a = ['A'; 'B'; 'C'; 'A'; 'B'; 'C'];
b = [1; 1; 1; 2; 2; 2];
c = ['N'; 'J'; 'N'; 'J'; 'N'; 'J'];
T = table(a,b,c)
T_new = unstack(T,2,1)
results in:
T =
6×3 table
a b c
_ _ _
A 1 N
B 1 J
C 1 N
A 2 J
B 2 N
C 2 J
T_new =
2×4 table
c A B C
_ _ _ _
N 1 2 1
J 2 1 2

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by