Find set of values that are unique to the values in first two columns in a table

17 visualizzazioni (ultimi 30 giorni)
I have a table like the following. Columns C1, C2, and C3. Based on the unique values on first two columns, I need to collect all the values in a vector. In the below table, I have 7 unique rows. For each unique row, lets say [3,1], i need to collect values from column C3 as a vector [2,5] etc. Also please note that the first column C1 is a categorical data. eg, date. Any help is appreciated. Thanks
C1 C2 C3
3 1 2
3 1 5
3 3 1
1 3 3
3 2 3
2 3 3
1 1 3
1 2 3
2 3 2
3 3 2
3 3 8
3 3 1
1 3 10
  1 Commento
the cyclist
the cyclist il 24 Nov 2019
It would be easier to help if you uploaded the actual table (or a representative sample) in a *.mat file. This will prevent us from having to guess at exactly how your data are stored, what the date type is, etc.

Accedi per commentare.

Risposta accettata

Ridwan Alam
Ridwan Alam il 24 Nov 2019
Modificato: Ridwan Alam il 24 Nov 2019
I believe what you are looking for is the unique() function, specially the z in the example below:
>> mytable
mytable =
5×3 table
Var1 Var2 Var3
___________ ____ ____
20-Nov-2019 92 57
21-Nov-2019 29 8
22-Nov-2019 76 6
22-Nov-2019 76 54
24-Nov-2019 39 78
>> [x,y,z]=unique(mytable(:,1:2))
x =
4×2 table
Var1 Var2
___________ ____
20-Nov-2019 92
21-Nov-2019 29
22-Nov-2019 76
24-Nov-2019 39
y =
1
2
3
5
z =
1
2
3
3
4
Using "z" you can sort out your third column values. One way to do:
newVar = {};
for i = 1:max(z)
newVar{i} = table2array(mytable(z==i,3))';
end
Please let me know how it goes.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by