fprintf multiple column string

18 ビュー (過去 30 日間)
Steamboat Rock
Steamboat Rock 2018 年 4 月 3 日
回答済み: Steamboat Rock 2018 年 4 月 3 日
I have imported a large file of numbers and letters into Matlab as a string. In short, after some number edits (which I know how to do), I am attempting to then use fprintf to save this to a new file. However, only the first column of the string is being saved. How do I save all the columns?
The input file and output file are shown in images.
Here is the code (the imported file is saved as variable S):
fileID = fopen('newfile.in','w');
fprintf(fileID, '%s\n', S);
fclose(fileID);
  1 件のコメント
Bob Thompson
Bob Thompson 2018 年 4 月 3 日
編集済み: Bob Thompson 2018 年 4 月 3 日
What file format is fileID?
I ask because fprintf() is intended to print strings out into a text or ascii format file, but your images appear to be almost an excel format. fprintf will not work properly printing to an excel file.
If that is a .csv file type then fprintf will work, but most likely still not properly delineate the different columns as it is intended to print single column lines of text, not string data to multiple columns.

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

採用された回答

Steamboat Rock
Steamboat Rock 2018 年 4 月 3 日
I figured out how to do it...
for i=1:length(S(:,1))
fprintf(fileID, '%s ',S(i,:)');
fprintf(fileID,'\n');
end
Cheers!

その他の回答 (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