MATLAB: How to write different length and different datatypes data to a text file from matlab

Right now I can only write a fixed length data to the text file ,but I need to change to a variable length data. My code:
fileID = fopen(logfilePathLocal,'at+');
formatSpec = '%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n';
fprintf(fileID,formatSpec,data{1,:});
fclose(fileID);

Best Answer

Width = size(data, 2);
formatSpec = ['%s', repmat(',%d', 1, Width - 1), '\n'];
Or:
fileID = fopen(logfilePathLocal,'at+');
fprintf(fileID, '%s', data{1,1});
fprintf(fileID, ',%d', data{1,2:end});
fprintf(fileID, '\n');
fclose(fileID);
I don't know, what is faster or easier.