The writematrix command can write matrices to text files. For example, for a matrix like the following
A = [1, 2, 3, 4];
It can be written to file a.txt
using the writematrix command
A = [1, 2, 3, 4];
writematrix(A, 'a.txt', 'WriteMode', 'append', 'Delimiter', ' ');
The output is
1 2 3 4
But if I want the output like below
1.0000 2.0000 3.0000 4.0000
How do I go about using writematrix?
CodePudding user response:
Convert A
into a character array with num2str
in the required format before using writematrix
i.e.
writematrix(num2str(A,'%.4f '), 'a.txt', 'WriteMode', 'append', 'Delimiter', 'tab');