I have a program based on some functionality and the results are displayed on 2 .csv files ( file1 and file2)
The files consists of same rows and columns, the columns are named as condition,supply1,supply2
I want to read both the files into the program, load them and then compare the contents of supply1,supply2, based on the condition and number.
We have compare the respective contents and display the difference of supply1 and suppy2 between those 2 files.
since you have both numbers and text, you can use textscan to read in each file into a Cell array. (if they were all numbers, you could just use csvread. but it will turn all text into zeros, and you said you need to retain the 'condition' data.)
>> file1 = fopen('file1.csv');
>> file2 = fopen('file2.csv');
>> data1 = textscan(file1, "%s,%f,%f,%d\n", "HeaderLines", 1, "Delimiter",",")
data1 =
{
[1,1] =
{
[1,1] = tb
[2,1] = tb
[3,1] = tb
[4,1] = ta
[5,1] = ta
[6,1] = tc
[7,1] = tc
[8,1] = tc
}
[1,2] =
1.070000
0.070000
1.170000
1.270000
1.370000
1.470000
1.470000
1.670000
[1,3] =
-1.1100
-1.2300
-1.6700
-1.5700
-1.3700
-1.0700
-1.4700
-3.9700
[1,4] =
1
2
3
1
2
1
2
3
}
>> data2 =
textscan(file1, "%s,%f,%f,%d\n", "HeaderLines", 1, "Delimiter",",");
data2 =
{
[1,1] =
{
[1,1] = ta
[2,1] = ta
[3,1] = tb
[4,1] = tb
[5,1] = tb
[6,1] = tc
[7,1] = tc
[8,1] = tc
}
[1,2] =
5.010000
0.070000
1.120000
3.340000
4.770000
4.500000
2.400000
1.550000
[1,3] =
-6.1100
-4.2300
-7.6700
-8.5700
-2.3700
-2.0700
-4.4700
-9.9700
[1,4] =
1
2
1
2
3
1
2
3
}
>> fclose(file1);fclose(file2);
You now have all of your data loaded and can do whatever math and comparisons you want, working with the cell arrays. Note that you index cells with { }, and the arrays within each cell element as usual with [ ]