MATLAB: How to pass many input arguments into a function at once

input argumentsisequal

Hi,
I'm using the isequal function to compare if certain table columns are equal.
I'm currently doing this by passing the name of the table columns in manually for each input argument like so:
correct_order = isequal(a.ID1,a.ID2,a.ID3,a.ID4, a.ID5);
However, as I'll have a different number of columns (e.g. a.ID1, a.ID2… a.IDn) each analysis, I want a way to pass all table columns that begin with 'ID' into the isequal argument at once.
Something along the lines of:
correct_order = isequal(a.ID*);
where * denotes a wildcard for all columns in table a that begin with 'ID'.
Thanks.

Best Answer

You can extract all columns of the for ID* using contains() as follow
requiredColumns = contains(TABLE.Properties.VariableNames, 'ID');
TABLEnew = TABLE{:, requiredColumns};
TABLEnew = num2cell(TABLEnew, 1);
isequal(TABLEnew{:})