필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 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