How to write data to text file with the same space before and after values?

5 ビュー (過去 30 日間)
Ahmad Bayhaqi
Ahmad Bayhaqi 2022 年 10 月 8 日
コメント済み: Ahmad Bayhaqi 2022 年 10 月 11 日
Hi, I want to write data to text file using fprintf. I want to get the output like the the attachment (expected). However, I got an output with messy space (result). Is there a way to handle this matter? I would very appreciate it.
  2 件のコメント
KSSV
KSSV 2022 年 10 月 8 日
What is the output you are trying to write into textfile? A matrix?
Ahmad Bayhaqi
Ahmad Bayhaqi 2022 年 10 月 8 日
Yes and like expected figure in the attachment.

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

採用された回答

KSSV
KSSV 2022 年 10 月 8 日
You need to proceed like shown below.
A = rand(4) ;% Demo matrix
[mrows, ncols] = size(A) ;
fmt = [repmat('%f ', 1, ncols) '\n'] ;
fprintf(fmt, A.')
0.083855 0.056709 0.874155 0.832302 0.279760 0.150683 0.822811 0.093508 0.877169 0.828942 0.578860 0.973929 0.607329 0.494551 0.707804 0.998606

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOther Formats についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by