MATLAB: How to concatenate each row of a matrix into a vector

concatenateMATLABmatrixnumber to stringrowvector

Hey there,
I have a matrix 1000×7 of double (only 0 and 1) like that :
0 0 1 1 0 0 0
0 0 1 1 0 0 0
1 0 1 1 0 0 0
...
0 0 1 1 0 0 0
0 0 1 1 0 0 1
0 0 1 0 0 0 0
For each row, I have to concatenate each column value to get a vector of strings like this
0011000
0011000
1011000
...
0011000
0011001
0010000
Do you have any idea of how could I do that ?

Best Answer

% create fake data
A = [0 0 1 1 0 0 0
0 0 1 1 0 0 1
0 0 1 0 0 0 0];
% Convert to char array
s = arrayfun(@(x)sprintf('%d',x), A)
% s =
% 3×7 char array
% '0011000'
% '0011001'
% '0010000'
% if desired, convert to cell array of strings
c = cellstr(s)
% c =
% 3×1 cell array
% {'0011000'}
% {'0011001'}
% {'0010000'}