How do you work with qualitative data in Matlab?

10 views (last 30 days)
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 Comment
Kelly Kearney
Kelly Kearney on 17 Sep 2015
How are you trying to reference the data? And what error are you getting?

Sign in to comment.

Accepted Answer

Kirby Fears
Kirby Fears on 17 Sep 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.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!