MATLAB: Problem with regexp and split, and picking some cells

MATLABmatlab code regexp ismember cells format string split

I have the following input:
>> data(1).Header
ans =
AF051909 |392-397:CAGCTG| |413-418:CAGGTG|
I needed to save them to cells as {'392-397', 'CAGCTG'; '413-418', 'CAGGTG';}
I so I used regexp to do so with the following code:
struKm(1).trueBinding = regexp(data(1).Header,'\s\||\:|\|','split');
this returns:
>> struKm(1).trueBinding
ans =
'AF051909' '392-397' 'CAGCTG' '' '413-418' 'CAGGTG' ''
as you can see there are to empty cells and I tried to find out why they are there but failed.
I also tried to ignore that and continue to picking up the cell that I need for the rest of my code which is 'CAGCTG' and 'CAGGTG'. I have this code to pick them up:
[r1,r2] = ismember(struKm(1).trueBinding,set)
it return zeros.
Can someone help with two issues please?
Regards, A.

Best Answer

you can maintain your code and add a line code to remove empty elements
data='AF051909 |392-397:CAGCTG| |413-418:CAGGTG|'
s=regexp(data,'\s\||\:|\|','split');
s(cellfun(@(x) isempty(x),s))=[]
Related Question