Double becomes int32 --why??

My goal is to write a file that has a column of double precision numbers for each subject. Here's what I have:
TadvDiff(1,qq) = currsubj; %Heading that displays subject ID number
TadvDiff(2:(timepoints+1),qq) = TminusC;
currsubj and TminusC are both double-precision. Somehow, TadvDiff is int32.
After looping through each subject, I write TadvDiff to a file:
dlmwrite('TadvDiffN108.txt',TadvDiff,'delimiter','\t','precision', '%.4f');
which ends up being all 1s and 0s when I need decimals. Why did my doubles become ints, and how can I correct this?
Thanks!

댓글 수: 5

ANJ
ANJ 2012년 6월 18일
I should maybe add that 1) I've read about precision problems with dlmwrite, but the value of TadvDiff is already an int32 before I call that function; and 2) I'm using the student version of Matlab, 7.10 if that is useful info.
Thanks again!
Walter Roberson
Walter Roberson 2012년 6월 18일
How did you initialize TadvDiff ?
ANJ
ANJ 2012년 6월 18일
The code that I've shown is the first time I've defined TadvDiff.
Walter Roberson
Walter Roberson 2012년 6월 18일
Somehow, the very first time you write into TadvDiff, you must be storing int32. That very first write determines the datatype after that.
Can you reasonably pre-allocate your TadvDiff array? e.g.,
TadvDiff = zeros(timepoints+1, 17);
ANJ
ANJ 2012년 6월 18일
Great, that did the trick! Thanks so much!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

ANJ
2012년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by