2.26 Convert list of separated numerical numbers to strings
Problem: given a list of numbers such as
{{1, 2},
{5, 3, 7},
{4}
}
convert the above to list of strings
{"12",
"537",
"4"}
| Mathematica
a={{1,2},{5,3,7},{4}};
Map[ToString[#]&,a,{2}];
Map[StringJoin[#]&,%]
|
List["12","537","4"]
|
| Matlab
a={[1,2],[5,3,7],[4]};
r=arrayfun(@(i) ...
cellstr(num2str(a{i})),1:length(a));
r'
|
ans =
'1 2'
'5 3 7'
'4'
|
| answer below is due to Bruno Luong at Matlab newsgroup
a={[1,2],[5,3,7],[4]};
map='0':'9';
cellfun(@(x) map(x+1), a, 'uni', 0)
|
'12' '537' '4'
|
| Maple
a:=[[1,2],[5,3,7],[4]];
map(x->convert(cat(op(x)), string),a);
|
["12", "537", "4"]
|