MATLAB: How to seperate a String at different positions

split string

Hallo MatLab-Pros,
I have a string which looks like this: "DAT00000706LR0106700000100000002+000000194018602202101-0002-00010+000+0000000000+000+000+071+072008009000600000000000+00000+206+2060230000000000402+0000+000+001"
I'm trying to seperate it into little pieces, which are defined by length from a seperate Array. The DAT in the start can be ignored.
exp.: A = ( 4 2 2 1 1 5 6 4 4 … and so on
So the new Array should somehow look like this:
0000 07 06 L R 01067 000001 0000 0002 … and so on
Thanks
Mike

Best Answer

You could use mat2cell to split the string into strings in a cell array (note that I added 3 to the start of A, so that it reads the DAT part separately):
>> str = 'DAT00000706LR0106700000100000002+000000194018602202101-0002-00010+000+0000000000+000+000+071+072008009000600000000000+00000+206+2060230000000000402+0000+000+001';
>> A = [3,4,2,2,1,1,5,6,4,4];
>> C = mat2cell(str(1:sum(A)),1,A);
>> C{:}
ans = DAT
ans = 0000
ans = 07
ans = 06
ans = L
ans = R
ans = 01067
ans = 000001
ans = 0000
ans = 0002