Reputation: 4391
I have a C++ program performing an iterative improvement procedure. I record the error in every step and I would like to import that data into octave to plot. My program writes the result as a matrix to a file named "err.m":
B = [
0 0.0566002;
1 0.0510102;
2 0.0510102;
3 0.0454972;
4 0.0418604;
5 0.0415802;
6 0.036775;
7 0.0298324;
8 0.0298324;
9 0.0298324;
]
(The actual file is of course much bigger.) As soon as I fire up octave and enter
load 'err.m'
I get the error
error: load: err.m: inconsistent number of columns near line 2
error: load: unable to extract matrix size from file `err.m'
However, when I paste the contents of the file into octave directly, everything works fine (unless the matrix has to many rows). I googled the error but I found no solution to my problem, although the problem seems to be rather common.
Does anyone know how I can load the file?
Upvotes: 1
Views: 1984
Reputation: 151
err.m:
0 0.0566002
1 0.0510102
2 0.0510102
3 0.0454972
4 0.0418604
5 0.0415802
6 0.036775
7 0.0298324
8 0.0298324
9 0.0298324
err1.m:
B = [
0 0.0566002;
1 0.0510102;
2 0.0510102;
3 0.0454972;
4 0.0418604;
5 0.0415802;
6 0.036775;
7 0.0298324;
8 0.0298324;
9 0.0298324;
];
In Octave:
octave:1> load 'err.m'
octave:2> err
err =
0.00000 0.05660
1.00000 0.05101
2.00000 0.05101
3.00000 0.04550
4.00000 0.04186
5.00000 0.04158
6.00000 0.03678
7.00000 0.02983
8.00000 0.02983
9.00000 0.02983
octave:3> err1
B =
0.00000 0.05660
1.00000 0.05101
2.00000 0.05101
3.00000 0.04550
4.00000 0.04186
5.00000 0.04158
6.00000 0.03678
7.00000 0.02983
8.00000 0.02983
9.00000 0.02983
octave:4> run 'err1.m'
B =
0.00000 0.05660
1.00000 0.05101
2.00000 0.05101
3.00000 0.04550
4.00000 0.04186
5.00000 0.04158
6.00000 0.03678
7.00000 0.02983
8.00000 0.02983
9.00000 0.02983
octave:5> B=load('err.m')
B =
0.00000 0.05660
1.00000 0.05101
2.00000 0.05101
3.00000 0.04550
4.00000 0.04186
5.00000 0.04158
6.00000 0.03678
7.00000 0.02983
8.00000 0.02983
9.00000 0.02983
Upvotes: 0