csvwriteWrite an array to a CSV file
csvwrite(path, A)A to a CSV file of the path path.A can be a numeric array or a character array.ndims(A) is larger than 2, it is first reshaped to a matrix before writing to the file.path should be a character vector representing the path of a file with extension .csv,.dat or .txt.csvwrite(path, A, r, c)path and A are as specified above.r is a real integer c is a real integer a to a file, and then read it back as b.path = './../csv/data/a.csv';
a = complex([1 2 3;4 5 6;7 8 9],[1 2 3;4 5 6;7 8 9])
csvwrite(path,a);
b = csvread(path)
a =
1.000 + 1.000i 2.000 + 2.000i 3.000 + 3.000i
4.000 + 4.000i 5.000 + 5.000i 6.000 + 6.000i
7.000 + 7.000i 8.000 + 8.000i 9.000 + 9.000i
Array written to debug/csv/data/a.csv successfully.
Array read from debug/csv/data/a.csv successfully.
b =
1.000 + 1.000i 2.000 + 2.000i 3.000 + 3.000i
4.000 + 4.000i 5.000 + 5.000i 6.000 + 6.000i
7.000 + 7.000i 8.000 + 8.000i 9.000 + 9.000i
a to a file, and then read it back as b. One zero row and 2 zero columns are appended to A when writing to the file. b returned from csvread has an extra row and 2 extra columns of zeros.path = './../csv/data/a.csv';
a = [1 2 3;4 5 6;7 8 9]
csvwrite(path,a,1,2);
b=csvread(path)
a =
1.000 2.000 3.000
4.000 5.000 6.000
7.000 8.000 9.000
Array written to debug/csv/data/a.csv successfully.
Array read from debug/csv/data/a.csv successfully.
b =
0.000 0.000 0.000 0.000 0.000
0.000 0.000 1.000 2.000 3.000
0.000 0.000 4.000 5.000 6.000
0.000 0.000 7.000 8.000 9.000