How can I split my data into categories

1 view (last 30 days)
Hi I have a cell data imported from Excel (variable name and corresponding class) like that
['AN1','ASA','AND','ANL','ABB','ACD','ACH','ACK','AYT','ALD'];
['stock','stock','stock','stock','bond','bond','bond','bill','bill','bill']
I want to convert this to structure or any useful type to apply a function to specified class. In other words, I want to apply a function to variables under each ('stock', 'bond', 'bill') class.
Thanks,

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 22 Jul 2015
a={'AN1','ASA','AND','ANL','ABB','ACD','ACH','ACK','AYT','ALD'}
b={'stock','stock','stock','stock','bond','bond','bond','bill','bill','bill'}
[ii,jj,kk]=unique(b)
for k=1:numel(ii)
data.(ii{k})=a(ismember(kk,k))
end

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!