Regarding "fwrite" in matlab
이전 댓글 표시
The following lines are a part of my code.
fid=fopen('M1.txt','w');
fwrite(fid,k,'int16');
fclose(fid);
I would like know how to include a delimiter. I need the .txt file to have 16 bits per line since this data has to be read line by line for further processing.
Kindly help me with this at the earliest.
Thank you
채택된 답변
추가 답변 (1개)
Titus Edelhofer
2012년 3월 19일
Hi Aparna,
are you sure you want to use fwrite? With fwrite you write binary data (open your M1.txt with an editor that can display HEX data). There is no "line" in a text file usually. Could it be that you want to use fprintf instead?
If this is not the case, you could just use fprintf for the delimiter, i.e., add
fprintf(fid, '\n');
Hope this helps,
Titus
댓글 수: 8
Aparna
2012년 3월 19일
Titus Edelhofer
2012년 3월 19일
Hi Aparna,
that's what I meant: I'm pretty sure you don't want the bits but "numbers". Try
k = 42;
fprintf(fid, '%d\n', k);
Does this what you need?
Titus
Geoff
2012년 3월 20일
Is the xilinx expecting Windows newlines? In that case you'll have to output CRLF, not just LF:
fprintf(fid, '%d\r\n', k)
Titus Edelhofer
2012년 3월 20일
Or use
fid=fopen('M1.txt','wt');
(note the 'wt' instead of 'w') to handle this automatically.
Titus
Walter Roberson
2012년 3월 20일
Not quite, Titus. Using 'wt' outputs CRLF only if you are running on an MS Windows operating system, which is information we are not given. Geoff's suggestion of \r\n with 'w' is needed if the generating code might be running on something other than MS Windows.
Aparna
2012년 3월 20일
Asadullah
2012년 10월 1일
편집: Walter Roberson
2012년 10월 1일
Try %u instead of %d. visit http://www.mathworks.co.uk/matlabcentral/answers/32703-regarding-fwrite-in-matlab to read more about it.
Walter Roberson
2012년 10월 1일
That link leads to this question.
카테고리
도움말 센터 및 File Exchange에서 AMD FPGA and SoC Devices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!