MATLAB: Separate rows that contain certain string character

cell arrayseparatestring

Hi all,
I would like to separate the rows of the cellarray bellow in to two cellarrays, depending on the string character on the third column, whether it ends in 'B' or 'L'.
For example, i have the cellarray:
a={
'STING ONE' 40843 '09L';
'STRING TWO' 40842 '10B';
'STRING THREE' 40841 '11L';
'STRING FOUR' 40840 '12B';
'STRING FIVE' 40839 '03L'}
I would like to split the above automatically into:
b={
'STING ONE' 40843 '09L';
'STRING THREE' 40841 '11L';
'STRING FIVE' 40839 '03L'}
and
c={
'STRING TWO' 40842 '10B';
'STRING FOUR' 40840 '12B'}
would that be possible to do?
Thanks very much in advance for your help!
Kind regards,
Kosta.

Best Answer

>> idx = cellfun(@(s)'B'==s(end),a(:,3));
>> c = a(idx,:)
You could even put this in a function:
>> fun = @(c)a(cellfun(@(s)c==s(end),a(:,3)),:);
>> b = fun('L');
>> c = fun('B');