フィルターのクリア

Problem using 'dlmwrite' into .txt file which contains 19/20 digit intergers

1 回表示 (過去 30 日間)
Apashanka Das
Apashanka Das 2021 年 12 月 10 日
コメント済み: Apashanka Das 2021 年 12 月 11 日
I have a csv file (id.txt) which contains two columns having 19/20 digit integers.
I am executing the following commands in matlab workspace :-
(1) load id.txt
(2) dlmwrite('id_new.txt',id,'delimiter','\t','precision','%19i')
After executing the above commands, the last 3/4 digits of 2nd column in the file 'id_new.txt' gets changed, although the 1st column remains as it is. Can anyone please help me in sort out this problem.
The screenshots of two files id.txt and id_new.txt are attached herewith.

採用された回答

Chunru
Chunru 2021 年 12 月 10 日
MATLAB double data type cannot hold so many digits in your imput data. It will round off the data to what-so-ever a double type can hold.
If you want to ensure that no information is lost, you can always read in the data as strings and then write the data as strings.
  17 件のコメント
Walter Roberson
Walter Roberson 2021 年 12 月 10 日
fid = fopen('A.txt');
A_data = cell2mat(textscan(fid, '%u64,%u64', 'headerlines',1));
fclose(fid)
fid = fopen('B.txt');
B_data = cell2mat(textscan(fid, '%u64', 'headerlines',0));
fclose(fid)
dlmwrite('id_new.txt',A_data, 'delimiter', '\t', 'precision', '%u')
Apashanka Das
Apashanka Das 2021 年 12 月 11 日
Thanks a lot sir, it worked, a great relief.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by