How to write all the character continuously

Hi guys. I got a question want to ask you guys. Below is my code.
string = uint8(retrieveblock);
export = sprintf('%d',string );
export = bin2dec(export);
char_export = char(export);
display(char_export);
fid = fopen('retrievedText.txt', 'w');
fwrite(fid, char_export);
fclose(fid);
This is within a for loop. my question is why I will just write the last character into the text file. Thanks and appreciate your opinion.

2 件のコメント

Jan
Jan 2013 年 3 月 1 日
You can edit the original question to improve the formatting of the code. I've inserted a blank line before and after the code.
Please use meaningful tags. All questions in this forum concern "Matlab".
Willam Willam
Willam Willam 2013 年 3 月 1 日
Oops. Sorry. Did got any ideas? :)

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

 採用された回答

Jan
Jan 2013 年 3 月 1 日

0 投票

You write all characters to the file, but all former characters are overwritten continuously.
You could open the file for appending instead of overwriting:
fid = fopen('retrievedText.txt', 'a');
But it would be much more efficient to open the file once only before the loop:
fid = fopen('retrievedText.txt', 'w');
for k = 1:1000
...
fwrite(fid, char_export);
end
fclose(fid);

1 件のコメント

Willam Willam
Willam Willam 2013 年 3 月 1 日
編集済み: Willam Willam 2013 年 3 月 1 日
Thanks ya Simon. The result is what I expected. Thank you very very much

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import and Export についてさらに検索

製品

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by