dictionary - Specified key type does not match the type expected for this container matlab -


i have cell_array 29136x1 cell value shows in workspace pallet. have map new_labels 4x1 map in workspace pallet. printing new_label on prompt gives

new_labels =     map properties:          count: 4       keytype: char     valuetype: double 

each entry in cell_array key in map, problem there type mismatch keytype in map char , entries of cell_array of type cell.

because of cannot access map , hence following:

arrayfun(@(x) new_labels(x), cell_array, 'un',0); 

gives error specified key type not match type expected container.

i tried converting char type using char_cell_array = char(cell_array) converts array of size 29136x4 means every entry 1 char , not string.

any appreciated.

if want use iterative way, have use cellfun. arrayfun operates on numeric arrays. because cell_array cell array, need use cellfun instead of arrayfun cellfun iterate on cell arrays instead.

however, you're after specifying more 1 key dictionary associated values. don't use arrayfun/cellfun that. there dedicated matlab function designed take in multiple keys. use values method built-in containers.map interface:

out = values(new_labels, cell_array); 

by using values(new_labels), retrieves of values in dictionary. if want retrieve specific values based on input keys, supply second input parameter cell array contains of keys want access in containers.map object. because have cell array, use second input values.

running example

>> = containers.map({1,2,3,4}, {'a','b','c','d'})  =     map properties:          count: 4       keytype: double     valuetype: char  >> cell_array = {1,2,2,3,3,4,1,1,1,2,2}; >> out = values(a, cell_array)  out =       'a'    'b'    'b'    'c'    'c'    'd'    'a'    'a'    'a'    'b'    'b' 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -