I want to sum files which I created with fprintf. I have 5 text files that contain something like this (1 column 8 rows):
0.1811
0.0889
-0.1073
-0.0777
-0.0596
0.0971
0.1021
0.3730
I’m trying to load those files into workspace and sum those columns. I could sum columns of two files, but with the last 3 files sums works only for last rows (row number 8). I understand it has something to do with loading and opening files. The last two files were loaded with:
SumFid=fopen(MyFile,'a'); %this is how my 2 files work opened
FID=fopen(FirstFile);
MatrixSub = load(FirstFile);
m = textscan(FID,'%f %f %f %f %f %f %f');
horzcat(m{:})
While for the other 3 files I’m using:
Wfid=fopen(VFile,'a');
Mat = load(VFile);
VData = fscanf(Wfid,'%f',[8,1]);
When I try to use same texscan and horzcat as with the previous two it gives error out of memory, but with the latter code it only sums last rows of those file contents when I try:
for i = i:8
Sum = A+B % this from first 2 files works
Sum3Files = file1+file2+files3;
end
I know it looks probably pretty trivial but I’m new in MATLAB and would appreciate your help much.
I think something like this is what you’re after: