How do you work with qualitative data in Matlab?

I am working with data from excel that is a table of inputs that look like DC001, DC002, DC003 and so on. Is there a way to work with this data? I'm having trouble because the entires contain letters. So when I import the data, each cell looks like 'DC001', 'DC002', 'DC003' and so on. I'm trying to count the occurrences of each but when I try to reference what's in the cell I get an error. Thanks

1 comentario

Kelly Kearney
Kelly Kearney el 17 de Sept. de 2015
How are you trying to reference the data? And what error are you getting?

Iniciar sesión para comentar.

 Respuesta aceptada

Kirby Fears
Kirby Fears el 17 de Sept. de 2015
Hi Jennie,
To access the contents of a cell, use curly braces.
>> X={'hey','hey','hi','hello'};
>> X{1}
ans =
hey
To count the number of times each name appears (names like DC001, DC002), I have some sample code below that should work for you.
>> X={'hey','hey','hi','hello'};
>> [uniqX,~,idx]=unique(X(:));
>> count=accumarray(idx,1);
>> countsummary=[uniqX,num2cell(count)]
countsummary =
'hello' [1]
'hey' [2]
'hi' [1]
The end result is a cell with unique names in the left column and the number of occurrences in the right column.
Hope this helps.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 17 de Sept. de 2015

Respondida:

el 17 de Sept. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by