フィルターのクリア

Write (and generate) text and numeric data into one txt file

1 回表示 (過去 30 日間)
Kyung Won Chang
Kyung Won Chang 2017 年 6 月 1 日
回答済み: dpb 2017 年 6 月 2 日
Hello Matlab gurus, I would like to have the following format of .txt file with a loop.
% at the 1st loop, write the following into .txt file
REGION s1-1
COORDINATE 1 1 1
/
% at the 2nd loop, the following is added to the pre-existing .txt file
REGION s1-2
COORDINATE 2 1 1
/
% at the 3rd loop, the following is added to the pre-existing .txt file
REGION s1-3
COORDINATE 3 1 1
/
...
% at th nth loop,
REGION s1-n
COORDINATE n 1 1
/
% Finally, in one .txt file I will have a series of data as shown above
Any tip would be grateful. Peter

回答 (1 件)

dpb
dpb 2017 年 6 月 2 日
>> fmt='REGION s1-%d\nCOORDINATE %d 1 1 \n/\n';
>> fprintf(fmt,[1:3;1:3])
REGION s1-1
COORDINATE 1 1 1
/
REGION s1-2
COORDINATE 2 1 1
/
REGION s1-3
COORDINATE 3 1 1
/
>>
Or, of course, you can call in a loop passing the single values each time.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by