フィルターのクリア

How to create a text file in a specific form of data arrangement

2 ビュー (過去 30 日間)
Preuk Tangpromphan
Preuk Tangpromphan 2017 年 10 月 4 日
コメント済み: Preuk Tangpromphan 2017 年 10 月 4 日
Hello, I'd like to know how to create a text file that can be used as input to another program
For example, this is my data
x = [1 2 3 4 5];
q = [6 7 8 9 10];
The text file should be in the form like this
x 5
1 2 3 4 5
Data
6 7 8 9 10
All data should be displayed in a row not column form.
The headers are x 5 and Data
*5 is the data count
I tried using frprint and read all the documents related but I still don't know how to do it.
I'm very new to MATLAB. Any help would be greatly appreciated.

採用された回答

KSSV
KSSV 2017 年 10 月 4 日
x = [1 2 3 4 5];
q = [6 7 8 9 10];
fid = fopen('data.txt','w') ;
fprintf(fid,'%s %d\n','x',length(x)) ;
fprintf(fid,'\n') ;
fprintf(fid,[repmat('%f ',1,length(x)),'\n'],x') ;
fprintf(fid,'\n') ;
fprintf(fid,'%s \n','Data') ;
fprintf(fid,'\n') ;
fprintf(fid,[repmat('%f ',1,length(q)),'\n'],q') ;
fclose(fid) ;
  1 件のコメント
Preuk Tangpromphan
Preuk Tangpromphan 2017 年 10 月 4 日
The code works very well. Thank you very much for your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by