0

I am trying to create a dictionary for which the keys are strings. I read an example doing this. However, in my case, I get

Error using containers.Map/subsasgn
Specified key type does not match the type expected for this container.

How is it different from the example in the link?

k = {}
k = [k,{'01'}];
k = [k, {'02'}];
m = containers.Map;
m(cellstr(k(1))) = 1
Community
  • 1
  • 1
giulio
  • 659
  • 2
  • 8
  • 22

1 Answers1

4

cellstr(k(1)) returns a cell type, not a string. So k{1} works:

k = {'01', '02'};
m = containers.Map;
m(k{1}) = 1

This code works for me, with MATLAB 2014b on Linux:

>>     k = {'01', '02'};
    m = containers.Map;
    m(k{1}) = 1

m = 

  Map with properties:

        Count: 1
      KeyType: char
    ValueType: any
Meng Wang
  • 277
  • 1
  • 8