MATLAB: Convert Array of Float to comma delimited string

float

Hi I would like to convert an array of floats to a single string, with commas separating the numbers, as below:
data = [1 2 3 4];
output = "1, 2, 3, 4"
However, I cannot seem to get the commas implemented – here is my attempt:
data2 = cellstr(num2str(data));
output = strjoin(data2, ', ');
i then get an output of;
'1 2 3 4'
What am I doing wrong?

Best Answer

data = [1,2,3,4];
strjoin(compose("%d",data),", ") % provides formatting control
ans = "1, 2, 3, 4"
strjoin(""+data,", ") % default formatting
ans = "1, 2, 3, 4"