Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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.

Réponse acceptée

Chunru
Chunru le 10 Déc 2021
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 commentaires
Walter Roberson
Walter Roberson le 10 Déc 2021
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 le 11 Déc 2021
Thanks a lot sir, it worked, a great relief.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by