フィルターのクリア

Adding semicolon and comma and saving it into .txt file

22 ビュー (過去 30 日間)
Lucas Stadnik
Lucas Stadnik 2019 年 10 月 31 日
コメント済み: Lucas Stadnik 2019 年 10 月 31 日
I have a vector (2x6001) and I want to save it to into a .txt file,. But before saving it , I also want to add a semicolon after every even position and a comma after every odd position:
Let's say:
x=(x1,x2,x3,x4,x5,...)
and I want sth like this:
x=(x1,x2;x3,x4;x5,...)
How can I do this?
I don't have access to the writematrix function, only dlmwrite
I tried delimiter, but all the data will get the same delimiter.

採用された回答

Ildeberto de los Santos Ruiz
Ildeberto de los Santos Ruiz 2019 年 10 月 31 日
Try this low-level code:
-----------------------------------------
x = randi(9,[1,2*6001]); % ACTUAL DATA
fileID = fopen('data.txt','w');
for k = 1:2:numel(x)-1
fprintf(fileID,'%g,%g;',x(k),x(k+1));
end
fclose(fileID);
-----------------------------------------
Enjoy!
  1 件のコメント
Lucas Stadnik
Lucas Stadnik 2019 年 10 月 31 日
Thank you so much. It worked.
I appreciate your help and time.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by