creating dictionary with a variable with the type double as the key and a cell array as value in matlab

To create a dictionary in Matlab with a variable of type double as the key and a cell array as the value, you can use the containers.Map class.

Here is an example code snippet:

main.m
% create a dictionary
myDict = containers.Map('KeyType', 'double', 'ValueType', 'any');

% add entries to the dictionary
key1 = 2.5;
val1 = {'apple', 'banana', 'orange'};
myDict(key1) = val1;

key2 = 3.8;
val2 = {'watermelon', 'kiwi', 'grape'};
myDict(key2) = val2;

% access the values in the dictionary
disp(myDict(key1));
disp(myDict(key2));
345 chars
16 lines

In the above code, we create a dictionary myDict with the key type double and the value type any (which allows for any type of value, including a cell array). We then add two entries to the dictionary, with double variables key1 and key2 as the keys and cell arrays val1 and val2 as the values. Finally, we access and print the values in the dictionary using the keys.

gistlibby LogSnag