How can I split my data into categories

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

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)

Community Treasure Hunt

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

Start Hunting!