MATLAB: How to set an index on a table

indexingMATLABreadtable

I have an csv file and am reading it using readtable(). I want to set a index on this table for fast access of data (something similar to set_index in python(pandas)).
T=readtable('file.csv');
index1=find(T.column1==value1);
index2=find(T.column2==value2);
index=intersect(index1,index2);
sam=table2array(T(index,6));
I want to do this for different values of value1 and value2 (approx 12000 times). This is taking about 600 seconds for 12000 records. Is there a way to access the table fast?
Thanks in advance.

Best Answer

MATLAB tables are not database objects, and do not have indexes like are created with pandas set_index.
You could improve performance by using
T=readtable('file.csv');
mask = T.column1 == value1 & T.column2 == value2;
sam = T{mask,6};
If you had a number of these to do then you could:
need_to_match = [value_1s_to_match(:), value_2s_to_match(:)];
[tf, idx] = ismember(T{:,1:2}, need_to_match);
Now all of the places that idx are 1 belong to the first array, 2 belong to the second case, and so on; idx will be 0 for rows that do not match any of the cases.
But before making a recommendation on how to best use the index, I would ask you to have a look at https://www.mathworks.com/help/matlab/ref/findgroups.html#buxwasl and say whether that looks like what you are trying to do.