csvreadReading an array from a CSV file
csvread(path)path.path should be a character vector representing the path of the file to be read.csvread(path, r1, c1)path is as described above.r1 is a real integer r1 == 0 refers to the first row in the file. r1 should be strictly less than the number of rows in the file.c1 is a real integer c1 = 0 refers to the first column in the file. c1 should be strictly less than the number of columns in the file.csvread(path, r1, c1, [r1 c1 r2 c2])path is as described above.r1 and r2 are real integers r1 and r2 should be strictly less than the number of rows in the file. Moreover, r1 <= r2 should hold.r1 in the second and the last arguments should have the same values.c1 and c2 are real integers c1 and c2 should be strictly less than the number of columns in the file. Moreover, c1 <= c2 should hold.c1 in the third and the last arguments should have the same values.a to a file, and then read it back as b.a = rand(3,4)
path = './../csv/data/a.csv';
csvwrite(path,a);
b = csvread(path)
a = 1e-1 ×
8.452 9.059 6.624 8.596
9.679 8.034 0.183 6.887
0.980 7.559 6.545 7.754
Array written to debug/csv/data/a.csv successfully.
Array read from debug/csv/data/a.csv successfully.
b = 1e-1 ×
8.452 9.059 6.624 8.596
9.679 8.034 0.183 6.887
0.980 7.559 6.545 7.754
r1 == 2) and the second column (c1 == 1).a=rand(3,4)
path='./../csv/data/a.csv';
csvwrite(path,a);
b=csvread(path,2,1)
a = 1e-1 ×
7.477 4.001 0.084 3.789
0.297 8.877 6.255 7.504
1.033 0.067 5.767 1.423
Array written to debug/csv/data/a.csv successfully.
Array read from debug/csv/data/a.csv successfully.
b = 1e-1 ×
0.067 5.767 1.423
r1 == 2, r2 == 2) and columns 2-3 (c1 == 1,c2 == 2) of a CSV file.% Input
a=rand(3,4)
path='./../csv/data/a.csv';
csvwrite(path,a);
b=csvread(path,2,1,[2 1 2 2])
% Output
a = 1e-1 ×
4.496 3.148 9.530 0.040
4.412 8.323 5.474 3.422
0.176 3.053 3.370 0.978
Array written to debug/csv/data/a.csv successfully.
Array read from debug/csv/data/a.csv successfully.
b = 1e-1 ×
3.053 3.370