reads a matrix from a text file
M = fscanfMat(filename[, fmt]);
[M, text] = fscanfMat(filename [, fmt]);
: :M output variable. A matrix of real numbers. : :text output variable. A column vector of strings. It is comments in
the beginning of the file filename.
:
The fscanfMat function is used to read a real matrix from a text file. The first non-numeric lines of the file are returned in text if requested and all the remaining lines must have the same number of columns (column separator are assumed to be white spaces or tab characters). The number of columns of the matrix will follow the number of columns found in the file and the number of lines is fetched by detecting eof in the input file. This function can be used to read back numerical data saved with the fprintfMat (default separator used is a space).
fscanfMat supports files encoded as ANSI/ASCII and UTF-8.
fd = `mopen`_(TMPDIR + "/Mat", "w");
`mfprintf`_(fd, "Some text.....\n");
`mfprintf`_(fd, "Some text again\n");
a = `rand`_(6,6);
for i = 1:6 ,
for j = 1:6, `mfprintf`_(fd, "%5.2f ", a(i,j));end;
`mfprintf`_(fd, "\n");
end
`mclose`_(fd);
a1 = fscanfMat(TMPDIR + "/Mat")
A = `ones`_(5,5) + 0.1;
`fprintfMat`_(TMPDIR + "/Matrix.txt", A, "%lg");
B = fscanfMat(TMPDIR + "/Matrix.txt", "%lg");
A == B
C = [%nan, %inf, -%inf, 1];
`fprintfMat`_(TMPDIR + "/MatrixNANINF.txt", C);
D = fscanfMat(TMPDIR + '/MatrixNANINF.txt')