MATLAB: How do you work with qualitative data in Matlab

qualitative data

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

Best Answer

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.