MATLAB: How to convert matrix to cell array of strings

cell arraymatrix manipulationstring

I want to convert the following:
mat = [1 2 3; 4 5 6 ; 7 8 9];
into the following array of strings,
arr = {'1,2(3)', '4,5(6)', '7,8(9)'};
How can I do that?

Best Answer

You could use sprintf.
mat = [1 2 3; 4 5 6 ; 7 8 9];
arr = cell(1, size(mat, 1));
for k = 1:numel(arr)
arr{k} = sprintf('%d,%d(%d)', mat(k,:));
end
arr =
'1,2(3)' '4,5(6)' '7,8(9)'