0
votes

I have a table in MATLAB, its data types are a mixture of cell-strings and cells. one of the table columns is 'Laterality' and the data is a cell-string.

I want to select all the data with Laterality = 'L'

So I do:

newTable = (table.Laterality == 'L')

as per the documentation: https://uk.mathworks.com/help/matlab/tables.html

However this gives the error:

Undefined function 'eq' for input arguments of type 'cell'.

I've tried changing the data type to chars. I've tried using the dataset type instead of the table. Any other suggestions?

1

1 Answers

1
votes

With cellfun function:

eq_L = cellfun(@(lat) strcmp(lat, 'L'), your_table.Laterality);
               % each cell content (named lat) is compared(*) with 'L'

or as recalled by @excaza, strcmp() can handle cell arrays:

eq_L = strcmp(your_table.Laterality, 'L');

Then

newTable = your_table(eq_L,:); % logical indexing

eq_L is an array of same size with logical values used for logical indexing.

(*) If every cell is only 1 character, then you could write lat == 'L'. But if some are more than 1 character (or empty), then you'll get an error comparing arrays of different sizes. strcmp() can handle both cases.