MATLAB: Selecting specifi sequence of cells from a matrix

multidimensional data sets

Hi, I have the price of one good (chocolate) that varies within one country (Greece) across time by store type, location, brand, pack size and whole market.
Using the following set of commands
%country
country=repmat({'Greece'}, [10,1]);
%product
prod=repmat({'chocolate'}, [10,1]);
%whole market
totalall1=repmat({'TTT'}, [5,1]);
totalall2=repmat({0}, [5,1]);
Totall=[ totalall1; totalall2];
%storetype
storetype1=repmat({'ST1'}, [2,1]) ;
storetype2=repmat({'ST2'}, [2,1]) ;
storetype3=repmat({'ST3'}, [2,1]) ;
storetype4=repmat({'ST4'}, [4,1]) ;
storetype=[storetype1; storetype2;storetype3;storetype4];
%location
location1=repmat({'l1'}, [3,1]) ;
location2=repmat({'l2'}, [3,1]) ;
location3=repmat({'l3'}, [4,1]) ;
location=[ location1; location2;location3];
%brand and pack size
bsk1=[repmat({'b1' }, [4,1]) repmat({'ps0' }, [4,1])];
bsk2=[repmat({'b2' }, [4,1]) repmat({'ps1' }, [4,1])];
bsk3=[repmat({'b2' }, [2,1]) repmat({'ps2' }, [2,1])];
bb=[bsk1;bsk2;bsk3];
myvarname = 'four_week';
eval([sprintf(myvarname) '=[021108 301108 281208 250109 220209 220309 190409 170509 140609 120709]']);
datemonthyear=four_week';
price=[1.4; 2;1.3;2.1;4.5;3;1.1;2.4;4;1];
mdata1 =[ country,prod, Totall, storetype, location, bb, num2cell(datemonthyear) num2cell(price) ];
I create this output
mdata1 =
Columns 1 through 6
'Greece' 'chocolate' 'TTT' 'ST1' 'l1' 'b1'
'Greece' 'chocolate' 'TTT' 'ST1' 'l1' 'b1'
'Greece' 'chocolate' 'TTT' 'ST2' 'l1' 'b1'
'Greece' 'chocolate' 'TTT' 'ST2' 'l2' 'b1'
'Greece' 'chocolate' 'TTT' 'ST3' 'l2' 'b2'
'Greece' 'chocolate' [ 0] 'ST3' 'l2' 'b2'
'Greece' 'chocolate' [ 0] 'ST4' 'l3' 'b2'
'Greece' 'chocolate' [ 0] 'ST4' 'l3' 'b2'
'Greece' 'chocolate' [ 0] 'ST4' 'l3' 'b2'
'Greece' 'chocolate' [ 0] 'ST4' 'l3' 'b2'
Columns 7 through 9
'ps0' [ 21108] [1.4000]
'ps0' [301108] [ 2]
'ps0' [281208] [1.3000]
'ps0' [250109] [2.1000]
'ps1' [220209] [4.5000]
'ps1' [220309] [ 3]
'ps1' [190409] [1.1000]
'ps1' [170509] [2.4000]
'ps2' [140609] [ 4]
'ps2' [120709] [ 1]
My question is the following. I want to develop a simple code that will enable me to find, for example, what the price of chocolate is in Greece when the product type is b1, location is l2, pack size is ps0, store type is st1 for the whole country (TTT). SO, I would like to get immediately the price that corresponds to a specific combination of store type, location, brand, pack size and whole market.
Thank you in advance, Stef

Best Answer

You might want to consider a relational database management system (RDBMS) such as mySQL. There is a little bit of learning curve but these type of operations are way more intuitive and easy to accomplish than with MATLAB.
Otherwise, what you have to do is:
idx = strcmp(mdata1(:,4),'st1') & strcmp(mdata1(:,6),'b1') & ...
mdata1{idx,end}