How to write a set of numbers into a text file using fprintf

조회 수: 1 (최근 30일)
Hi, Please help me in writing a set of numbers into a txt file.. a = [1.4 2.3 3.4 4.5]; fid = fopen('test.txt','wt') fprinf(fid,'%d %d %d %d\n',a);
Thanks & Regards, sowmya,.

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 5일
Your only real problem is that %d format is for printing integers and the values you want to print are not integral. You should be using %f, %e, or %g instead of %g if you want the fractional part printed out. If you do not want the fractional part printed out, then use the format you have now, but pass fix(a) or round(a) instead of a (depending whether you want truncation or rounding)
  댓글 수: 4
Jan
Jan 2011년 12월 5일
Again we see, that reading the error message carefully is very helpful. +1
DSP Masters
DSP Masters 2011년 12월 6일
Thank you soooo much
regards
sowmya..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by