Find unique rows in cell array with mixed data types
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
prp0rter
el 9 de Mayo de 2016
Comentada: prp0rter
el 13 de Mayo de 2016
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 comentarios
Respuesta aceptada
Ahmet Cecen
el 9 de Mayo de 2016
Editada: Ahmet Cecen
el 9 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!