How to change column size in table (.txt format) to make it look neater table?

4 ビュー (過去 30 日間)
Fashan Boby
Fashan Boby 2022 年 8 月 24 日
編集済み: Abderrahim. B 2022 年 8 月 25 日
I have a table file with .txt format, but it still looks messed up. I want to tidy it up so that each column in the table can fit the size and type of data I want. How to?

採用された回答

Abderrahim. B
Abderrahim. B 2022 年 8 月 24 日
編集済み: Abderrahim. B 2022 年 8 月 25 日
Hi!
Give a try using readtable, MATLAB will organize the variables (columns) for you. If the table is not what you expected, you will need to organize/ clean it by yourself.
Edit:
A small demo that compares fprintf and writetable.
% Generating some data
x = 0:0.2:1;
l = [10.0001 , 11.1 , 10.01, 9.01, 8.02, 0.002] ;
xl = [x.', l.'] ;
% Converting to table. Later need to convert to array.
tbl = array2table(xl) ;
% Writing to text file using fprintf
fileID = fopen('xl_fpf.txt','w');
fprintf(fileID, " x l\n") ;
for ii = 1:height(tbl)
fprintf(fileID,'%2.1f %4.4f\n',table2array(tbl(ii,:)));
end
fclose(fileID);
% Writing to text file using write table
writetable(tbl, "xl_wrtbl.txt", "Delimiter", " ")
Hope this helps
  2 件のコメント
Fashan Boby
Fashan Boby 2022 年 8 月 24 日
i mean, create new .txt file with neat table format like this :
Before =
After =
Abderrahim. B
Abderrahim. B 2022 年 8 月 25 日
編集済み: Abderrahim. B 2022 年 8 月 25 日
Hi!
Try to use fprintf, all you need to do is to set the format specifications. I ve included a demo in the answer, check out the the edit .

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by