MATLAB: Reading Data from container.Map Objects

containers.mapdatadata structureMATLABobscure behaviorstructstructure

I have created a container.Map object to store a structure as the value for a given key. The structure has two fields, the date which is a number and a remark for each date. While I could store this as a cell array (due to the different variable types), I like to use structures as it seems to help make the code more readable. I can populate the Map object with the data, unfortunately, when I try to list all of the remarks for a given key, it only returns one entry. What is the correct way to get a list of all the remarks for a given key?
I am running Matlab 8.1.0.604 (R2013a) with Java version 1.6.0_17-b04
Example code is as follows
% Create a new Map object
a = containers.Map;
% Create some silly data to store in it
times = datenum(2013, 1, 1, 0, 0, 0):1:datenum(2013, 1, 10, 0, 0, 0);
remarks = repmat({'Test String'}, 10, 1);
tmp = struct('Time', times, 'Remark', remarks);
% Insert the data into three different keys
a('One') = tmp;
a('Two') = tmp;
a('Three') = tmp;
% Now lets try to list all of the remarks associated with 'Two'
a('Two').Remark
I would like to be able to do something like:
{tmp.Remark}'
ans =
'Test String'
'Test String'
'Test String'
'Test String'
'Test String'
'Test String'
'Test String'
'Test String'
'Test String'
'Test String'
I would like to replace the tmp. in the last command to something like
{a('Two').Remark}'
When I do that I only get one line back. Thanks for any help on this.

Best Answer

I think I got it while writing the comment above.
v = a('Two')
Returns a 10x1 struct. If you look at the output from
v.Time
you'll see ans 10 times, each time with all 10 values.
If you look at:
v.Remark
You'll see test string printed for ans 10x. What is happening is containers.Map's subsref is only extracting the last value since it is not supported for cells or structs. This is just like it would appear at the command line:
y = v.Remark
z = v.Time
Either way, I think this is a fair enhancement request. Why do you want to nest structures inside of a containers.Map object?