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 Kommentar

How are you trying to reference the data? And what error are you getting?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kirby Fears
Kirby Fears am 17 Sep. 2015

0 Stimmen

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.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by