テキストファイルから行列を読み込む
M = fscanfMat(filename[, fmt]); [M, text] = fscanfMat(filename [, fmt]);
スキャンするファイルの名前を指定する文字列.
a character string giving the format. This is an optional
parameter, the default value is "%lg"
.
Supported format: %[width].[precision]type
or %type
where:
width
: optional number that specifies
the minimum number of characters output;
precision
: optional number that
specifies the maximum number of characters printed for all
or part of the output field, or the minimum number of
digits printed for integer values.
type
: lf, lg, d, i, e, f, g (see scanf_conversion).
出力変数. 実数の行列.
出力変数. 文字列の列ベクトル.
ファイルfilename
の先頭のコメントです.
fscanfMat
関数はテキストファイルからスカラー行列を読み込むために
使用されます.
text
が指定された場合,ファイルの先頭の非数値の行が
返されます.残りの行の列の数は同じである必要があります
(コロンセパレータは空白文字またはタブ文字であるとみなされます).
行列の列の数はファイルでみつかった列の数となり,
行の数は入力ファイルの終端を検出するまでに取得した行数と
なります.
この関数はfprintfMat
で保存した数値データを
読み戻すために使用することができます.
fscanfMat
は,ANSI/ASCII および UTF-8でエンコードされた
ファイルをサポートします..
CSV形式のファイルを読み込む場合, csvRead関数の使用が推奨されます.
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') | ![]() | ![]() |