mprintf
変換, 整形し, Scilab主ウインドウにデータを書き込む
printf
変換, 整形し, Scilab主ウインドウにデータを書き込む
呼び出し手順
mprintf(format,a1,...,an);
パラメータ
- format
残りのオペランドを書く際のフォーマットを定義するScilab文字列. formatオペランドは,C言語のprintfのformatオペランドと 構文にできるだけ近くなるよう作成されています, as described in the printf_conversion page. UTF-8 extended characters and numbered placeholders "%n$.." are supported.
- a1,...,an
formatパラメータに基づき変換,出力されるデータを定義します. Supported types: all numbers, booleans, strings. Only the real part of complex numbers is considered (current Scilab limitation).
説明
mprintf(format, a1, a2, ..)
replaces placeholders provided inside the
format
string with values of a1
, a2
, ..
converted according to each respective placeholder directive, and writes the result to
the Scilab console.
If a1
, a2
, .. are arrays with multiple rows,
they are processed row by row: the format is used iteratively for every row of the
arrays (horizontally "concatenated"), until the bottom
of the least tall array is reached. Remaining rows of taller arrays (if any) are ignored.
See examples.
If the total number of columns of a1
, a2
, ..
is bigger than the number of placeholders in the format
,
then extra columns are ignored.
The mprintf
function is an extended interface for C-coded
printf
.
例
I = (1:4)'; A = [26.93 ; 63.25 ; 40.51 ; 91.84]; B = [ 3.62 ; 15.04 ; 25.3 ; 48.19]; C = [ 4.37 28.06 48.18 %inf 41.48 %nan 26.39 77.83]; Status = ["NOK" "NOK" "NOK" "OK"]'; Format = "Iteration %d: Results: A= %f B= %2d%% Status= %3s C(1)= %g C(2)= %e\n"; mprintf(Format, I, A, B, Status, C);
--> mprintf(Format, I, A, B, Status, C); Iteration 1: Results: A= 26.930000 B= 3% Status= NOK C(1)= 4.37 C(2)= 2.806000e+01 Iteration 2: Results: A= 63.250000 B= 15% Status= NOK C(1)= 48.18 C(2)= Inf Iteration 3: Results: A= 40.510000 B= 25% Status= NOK C(1)= 41.48 C(2)= Nan Iteration 4: Results: A= 91.840000 B= 48% Status= OK C(1)= 26.39 C(2)= 7.783000e+01
Supernumerary columns or rows are ignored:
A = [%T %F %T %T %F]'; B = [ 4.37 28.06 48.18 %inf 41.48 %nan ]; mprintf("OK? %s Value: %4.1f\n", A, B);
--> mprintf("OK? %s Value: %4.1f\n", A, B); OK? T Value: 4.4 OK? F Value: 48.2 OK? T Value: 41.5
Numbered placeholders "%n$.." allow reordering printed data with the format:
names = ["Peter", "Martha" "John"]'; ages = [32 25 8]'; mprintf("%2$6s is %1$d-year old.\n", ages, names);
--> mprintf("%2$6s is %1$d-year old.\n", ages, names); Peter is 32-year old. Martha is 25-year old. John is 8-year old.
参照
- printf_conversion — mprintf, msprintf, mfprintf 変換仕様
- disp — 変数を表示
- write — フォーマットされたファイルに書き込む
- %io — 標準入力および標準出力を保持する変数(ファイル記述子).
- %chars — Selected sets of Unicode characters
履歴
バージョン | 記述 |
6.1.0 | Numbered placeholders "%n$.." are supported in the format. |
6.1.1 | Input data can be boolean. |
Report an issue | ||
<< disp | Output functions | msprintf >> |