Friday, November 3, 2017

Convert a vector or array of numbers into a comma separated CSV string


Lets say A is vector or numbers or integers and you want to add a separator "," or ".,"

A=[1:10]
for j=1:length(A);
%Here ".," is the separator, you can use other separator also
C{j}=sprintf('%s.,',num2str(A(j)));
end;
cell2mat(C)

Output
1.,2.,3.,4.,5.,6.,7.,8.,9.,10

If you want comma only then you can use "," as a separator in sprintf

No comments:

Post a Comment