Hi Xander,
I am assuming that you already have a cell array which contains tables as cells.
For this example we will consider the following structure:
TableName T1 ; Columns: Age,Height,Weight,BloodPressure,LastName
TableName T2 ; Columns: Age,Height,Weight,BloodPressure,LastName
CellArray tableAsCells; Rows: T1; T2 Step 1: Fetch a Table from the cell array :
>> grabATable = tableAsCells{1};
Step 2: Fetch columns from the table that you want to keep as keys:
>> keySets = table2cell(grabATable(:,5));
The function "table2cell" will convert the 5th column of the table elements into a cell array , which will act as our keys in the container.Map object.
Step 3: Fetch column from the table to be the values:
>> valueSets = table2cell(grabATable(:,3));
The function "table2array" will convert the 5th column of the table elements into a cell , which will act as our values in the container.Map object. NOTE: We could also use "table2array" function here.
Step 4: Put the keySets and valueSets in a container.Map object:
>> mapObj = containers.Map(keySets,valueSets);
Step 5: Fetching values form the map.
>> mapObj('Any_Key_From_keySets_cell_array');
For Example:
More information on "table2cell" , "table2array" and "containers.Map" can be found in the documentation links below:
Note: If you have to append in the map, if can be only done column wise.
I have attached a sample code to try this.
Hope this helps.
Thanks
Sudhanshu Bhatt
Best Answer