Strange behavior of diff()
이전 댓글 표시
Hi all,
I'm using 2012b and I'm trying to find the difference between successive elements of a vector of uint64 numbers. Here's some of them, but I get very puzzling results form diff(). For instance:
a = [4648759972
4648759972
4651621722
4652352784
4652733003
4653926753]
Then diff(a) gives the wrong result:
[5166781
5166781
2305031
1573969
1193750]
However diff(a(1:2)) gives the correct result: 0. Also diff(a(2:3)) gives the correct result: 2861750
I've been searching for an explanation but I did not find a similar problem ever reported, and I don't understand what is happening. Can anybody explain to me what is going on here?
Thanks a lot!
Paul
댓글 수: 8
>> a = uint64([4648759972 4648759972 4651621722 4652352784 4652733003 4653926753]);
>> diff(a)
ans =
0 2861750 731062 380219 1193750
>> ver
---------------------------------------------------------------------
MATLAB Version: 8.0.0.783 (R2012b)
...
>>
Try clear diff first, then retry...
Oh, and which diff before clear just for grins might be informative.
Stephen23
2016년 2월 25일
>> a = uint64([4648759972 4648759972 4651621722 4652352784 4652733003 4653926753])
a =
4648759972 4648759972 4651621722 4652352784 4652733003 4653926753
>> diff(a)
ans =
0 2861750 731062 380219 1193750
As illustrated above I don't see that problem with R2012b here using either numeric class; double or uint64.
John BG
2016년 2월 27일
tried
a = [4648759972 4648759972 4651621722 4652352784 4652733003 4653926753]
b=diff(a)
a_uint=uint64(a)
b_uint=diff(a)
all look fine in R2015a
Once had odd results with R2012a, reinstalled and it was fine. Have you tried to reinstall?
regards
John
Jan
2016년 2월 27일
What does
which diff -all
reply for uint64?
Walter Roberson
2016년 2월 27일
And to ask more directly,
which diff(uint64(0))
that will ensure you get the correct function shown for whatever uint64 is resolving to for you.
Paul
2018년 3월 14일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!