Find unique rows in cell array with mixed data types
36 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
First I'm used to working in database structures where you have a table with a primary key linked to a table with foreign key. In matlab, I need to read an xls file where all the data is in one file. For example,
raw =
ID Type Customer Allergies SomeNumber Topping
1 pizza John NaN 9 Pepperoni
1 pizza John NaN 9 Mushrooms
1 pizza John NaN 9 Peppers
2 pizza Jill NaN NaN Olives
2 pizza Jill NaN NaN Canadian Bacon
I would then like to put this in a struct where the toppings are an array and the unique row values are represented one time. I tried using unique() but couldn't perform on a mixed cell array. Any ideas how to extract the unique information and then attach the non-unique elements? I ultimately want to construct a class with each entry so that I can loop through and output data to a different format.
0 Commenti
Risposta accettata
Ahmet Cecen
il 9 Mag 2016
Modificato: Ahmet Cecen
il 9 Mag 2016
I cannot recreate your problem. Here is what I did:
AA = {'A','B','A','C'};
BB = [1 2 1 1];
CC= [true,true,true,false];
Z=table(AA',BB',CC')
Var1 Var2 Var3
____ ____ _____
'A' 1 true
'B' 2 true
'A' 1 true
'C' 1 false
then simply:
unique(Z)
ans =
AA BB CC
___ __ _____
'A' 1 true
'B' 2 true
'C' 1 false
Correctly gives unique rows. IT is also possible I didn't understand your problem.
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!