MATLAB: Find Data in Table

columnsdatafindMATLABqualitativerowssorttable

As a follow up question, my data is also inconsistent in how it is described. For example items 10 and 11 in my new table:
11×6 table
ID Speed Time Fruit1 Fruit2 Fruit3
__ _____ ____ _______ ________ ____________
1 3 9 'Apple' 'Jam' 'Cake'
2 6 5 'Cake' 'Orange' 'Jam'
3 3 4 'Jam' 'Cake' 'Apple'
4 5 2 'Jam' 'Orange' 'Cake'
5 9 4 'Jam' 'Jam' 'Orange'
6 5 3 'Pear' 'Jam' 'Cake'
7 3 5 'Cake' 'Cake' 'Cake'
8 2 3 'Jam' 'Cake' 'Apple'
9 5 3 'Jam' 'Orange' 'Jam'
10 7 1 'Jam' 'Jam' 'JamApple'
11 1 4 'Jam' 'Jam' 'OrangeCake'
Is it possible to include the JamApple as a type of Apple please?

Best Answer

Using categorical for the string columns has some advantages. I fixed up your listing above to be able to read as a table via
> t=readtable('cox.dat');
>> whos t
Name Size Bytes Class Attributes
t 10x6 2848 table
>> t.Properties
ans =
Description: ''
VariableDescriptions: {}
VariableUnits: {}
DimensionNames: {'Row' 'Variable'}
UserData: []
RowNames: {}
VariableNames: {'ID' 'Speed' 'Time' 'Fruit1' 'Fruit2' 'Fruit3'}
>>
With that it's easy enough to write
>> ix=any(ismember(t{:,4:6},{'Apple';'Orange'}),2); % find any row with apple or orange
>> t(ix,:) % display those found
ans =
ID Speed Time Fruit1 Fruit2 Fruit3
__ _____ ____ ______ ______ ______
1 3 9 Apple Jam Cake
2 6 5 Cake Orange Jam
3 3 4 Jam Cake Apple
4 5 2 Jam Orange Cake
5 9 4 Jam Jam Orange
8 2 3 Jam Cake Apple
9 5 3 Jam Orange Jam
10 7 9 Jam Jam Apple
>>
Use the logical index vector to access any other variable of interest.
It would be better going forward, of course, to normalize the database to put the three disparate properties in their own variable.