write matrix into .txt file
Show older comments
i have a matrix like this
A=
10 5 0
12 7 3
15 8 5
19 9 6
i want to add a letter before each element in this matrix , while first column is x-axis values , 2nd column is y-axis values and 3rd column is Z-axis values.
i need to write a capital letter of X before each value of first column elements and letter Y before each value and the same with 3rd column with Z letter like this
X10 Y5 Z0
X12 Y7 Z3
X15 Y8 Z5
and so on. And after that i need to add this word of ( G1 ) before each line ( or each row of the matrix ) like this
G1 X10 Y5 Z0
G1 X12 Y7 Z3
G1 X15 Y8 Z5
and last thing to add in capital letter of N followed by the number of the line like this
N1 G1 X10 Y5 Z0
N2 G1 X12 Y7 Z3
N3 G1 X15 Y8 Z5
and save all of these into text file editable with notepad and other software
i need to know what is the functions to use and how to apply them to make this edit i want
thanks
Tarek
Accepted Answer
More Answers (1)
Image Analyst
on 2 Jul 2017
Try this:
A= [...
10 5 0
12 7 3
15 8 5
19 9 6]
fid = fopen(filename, 'wt');
for row = 1 : size(A, 1)
fprintf(fid, 'N%d G1 X%d Y%d Z%d\n', ...
row, A(row, 1), A(row, 2), A(row, 3))
end
fclose(fid)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!