MATLAB: Reshaping a Char Array

arraycharacterMATLABreshape

Hi,
I am currently working on a Project where I need to order a Char Array like shown below
A = ['12';'12';'12';'12';'12';'12';'12';'12';'34';'34';'34';'34';'34';'34';'34';'34';'56';'56';'56';'56';'56';'56';'56';'56';'78';'78';'78';'78';'78';'78';'78';'78';'AA';'AA';'AA';'AA';'AA';'AA';'AA';'AA';'BB';'BB';'BB';'BB';'BB';'BB';'BB';'BB';'CC';'CC';'CC';'CC';'CC';'CC';'CC';'CC';'DD';'DD';'DD';'DD';'DD';'DD';'DD';'DD'];
I want to re-arrange the char array like:
'1234'
'1234'
'1234'
'1234'
'1234'
'1234'
'1234'
'1234'
'5678'
'5678'
'5678'
'5678'
'5678'
'5678'
'5678'
'5678'
'AABB'
'AABB'
'AABB'
'AABB'
'AABB'
'AABB'
'AABB'
'AABB'
'CCDD'
'CCDD'
'CCDD'
'CCDD'
'CCDD'
'CCDD'
'CCDD'
'CCDD'
What is the best way to do that? I tried using reshape function but it doesn't seem to work for this case?
Thanks in advance.

Best Answer

This should do it:
A = ['12';'12';'12';'12';'12';'12';'12';'12';'34';'34';'34';'34';'34';'34';'34';'34';'56';'56';'56';'56';'56';'56';'56';'56';'78';'78';'78';'78';'78';'78';'78';'78';'AA';'AA';'AA';'AA';'AA';'AA';'AA';'AA';'BB';'BB';'BB';'BB';'BB';'BB';'BB';'BB';'CC';'CC';'CC';'CC';'CC';'CC';'CC';'CC';'DD';'DD';'DD';'DD';'DD';'DD';'DD';'DD'];
B=mat2cell(A,ones(size(A,1),1),2);
B=reshape(B,8,[]);
part1=B(:,1:2:end);part1=part1(:);
part2=B(:,2:2:end);part2=part2(:);
B=cell2mat([part1 part2]);
Related Question