MATLAB: Manipolation of Cell Arrays.

cellcell arraycell arrays

I have {A}=<250×22>cell. thanks to another question I'm able to know the pairs of two colums of {A} for example I have just these three combination :{a}&{b} or {b}&{z} or {r}&{t}. What I would like to create three different cell arrays based on the three combination.

Best Answer

A={'a','b',1 2 3;
'a','b',3 4 5;
'b','z',3 4 5;
'b','z',4 5 6;
'r','t',5 6 7;
'r','t',6 7 8};
UniqComb={'a','b';'b','z';'r','t'};
N=size(UniqComb,1);
Groups=cell(N,1);
for k=1:N
index=and(strcmp(A(:,1),UniqComb(k,1)),strcmp(A(:,2),UniqComb(k,2)));
Groups{k}=A(index,:);
end
>> Groups{1}
Groups{2}
Groups{3}
ans =
'a' 'b' [1] [2] [3]
'a' 'b' [3] [4] [5]
ans =
'b' 'z' [3] [4] [5]
'b' 'z' [4] [5] [6]
ans =
'r' 't' [5] [6] [7]
'r' 't' [6] [7] [8]