MATLAB: How to transform data from rows to columns, based on a specific column

transform column into multiple

Currently i have a cell array containing a batch ID in de 1st column, and a position in the 2nd column. An example is shown below.
Batch Pos
001 1
001 3
001 8
002 1
003 5
003 8
007 2
007 4
007 7
007 8
011 6
013 2
014 1
014 3
014 5
014 6
What I am trying to achieve is to have only 1 row per batch ID, and convert the pos to seperate column with either True or 1. The pos will always be a number between 1 and 8.
Batch Pos 1 Pos 2 Pos 3 Pos 4 Pos 5 Pos 6 Pos 7 Pos 8
001 TRUE TRUE TRUE
002 TRUE
003 TRUE TRUE
007 TRUE TRUE TRUE TRUE
011 TRUE
013 TRUE
014 TRUE TRUE TRUE TRUE
Can anyone help me in the right direction how to achieve this, since i am really struggling with this.

Best Answer

A={'001' 1
'001' 3
'001' 8
'002' 1
'003' 5
'003' 8
'007' 2
'007' 4
'007' 7
'007' 8
'011' 6
'013' 2
'014' 1
'014' 3
'014' 5
'014' 6}
c1=A(:,1)
c2=cell2mat(A(:,2));
n=max(c2);
[ii,jj,kk]=unique(c1,'stable');
t=zeros(numel(ii),n);
for k=1:numel(ii)
idx=c2(kk==k);
t(k,idx)=1;
end
s=genvarname(repmat({'pos'},1,n+1));
s(1)={'patch'};
out=[[s;[ii num2cell(t)]]]