MATLAB: Filter Table with Generalized Values

filtertable

I have the following table say t =
Id Age Gender Country
— —– ——— ———
1 10 M US
2 20 F CA
3 20 F US
4 10 M CA
5 10 M CA
I have another array say col_name with values { Age = 20, Gender = F }
Values of col_name change .. for example col_name = { Age = 10, Gender = M, Country = CA }
or col_name = { Age = 10 }
My goal is to write a genealized function such that when i pass col_name ( whatever be its value ) it should be able to get me a filtered set from t
Is there an function for t that can help me get the filtered result set if I passed col_name ?
ex = t.<some_filter_function>( col_name = { Age = 20, Gender = F } )
should give me
Id Age Gender Country
— —– ——— ———
2 20 F CA
3 20 F US

Best Answer

Neeraj - how about trying something like
filteredTable = t(t.Age == 20 & strcmp(t.Gender, 'F'), :)
or are you hoping for something a little more general?