MATLAB: How to add character such as x,y,z with the numbers in a matrix

convert coordinate data to machine readable format

I have generated x,y,z coordinates of a surface that i want to give to the CNC machines. But the problem is machine only accepts the coordinates in this format
x189.23,y171.2,z18.3
x190.02,y172.4,z19.1
x191.52,y172.8,z18.5
x189.23,y171.2,z18.3
x190.02,y172.4,z19.1
x191.52,y172.8,z18.5
I have a matrix (1000×3) and i do not want to paste it in excel everytime to concatenate the character and the number. If there is an easy way to do it in matlab.
My second question is how to generate a text file of coordinates with character(e.g. x,y,z) as prefix from CSV file.

Best Answer

fid = fopen(FileName, 'r');
if fid == -1
error(Cannot open file for reading: %s', FileName);
end
Data = fscanf(fid, '%f,%f,%f');
fclose(fid);
fid = fopen(NewFileName, 'w');
if fid == -1
error(Cannot open file for writing: %s', NewFileName);
end
Data = fprintf(fid, 'x%.1f,x%.1f,z%.1f\n', Data);
fclose(fid);