mapping keys and values from a cell array of strings

514 views Asked by At

My Data comes back from a database query into matlab as the following:

{10000 by 1 cell}
[10000 by 1 double]
[10000 by 1 double]
[10000 by 1 double]
[10000 by 1 double]  

The first element is a bunch of sharecodes - (not unique, some repeat)

The next four elements are, for example:

bids, offers, traded price, close price 

I use share_codes = data{1} which could give me the sharecodes (but they're still a cell)

I want to map the share codes to a number which will allow me to work on them in matrix format.

I can use

keySet = {sharecode1, sharecode2, sharecode3}

I can use

valueSet = [1,2,3]

I can use

newMap = containers.Map(keySet, valueSet)

However I now want to create a new matrix from the cellarray i.e. which looks into data{1} and now instead of having the sharecodes it now has the mapped numbers.

So a cell array which was

sharecode1, sharecode2, sharecode3, sharecode2    

is now a matrix with

1, 2, 3, 2

I would say the real issue is the first element of the cell array is a bunch of strings.

1

There are 1 answers

0
user2126062 On

the cellfun function works and is able to return the strings from data{1} (which was a cellarray) as a coloumn vector in the form of type 'double'

strings_in_numbers = cellfun(@(x),mapObj(x), share_codes)

(found after help from a friend).