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 件のコメント

dpb
dpb 2016 年 2 月 25 日
編集済み: dpb 2016 年 2 月 25 日
>> 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
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
Paul
Paul 2016 年 2 月 26 日
編集済み: Paul 2016 年 2 月 26 日
Hi all, thanks for your quick responses.
which diff yields the standard Matlab path in /datafun/. Clearing diff had no effect. Adding the uint64 indicator for my variable, as Stephen suggested, sadly gives me the same results as before... Obviously I can code a quick and dirty workaround so I'm not in a tight spot but, it is very puzzling isn't it?
[edit] Ok, so, if I change the class of my variable into double, it works no problem, so diff(double(a)) works correctly.
I've also figured out what is exactly going wrong in the case of diff(uint64(a)). Instead of doing [X(2)-X(1) X(3)-X(2) .. X(N+1)-X(N)], it does [X(end)-X(end-1) X(end)-X(end-2) ... X(end)-X(1)]
dpb
dpb 2016 年 2 月 27 日
編集済み: dpb 2016 年 2 月 27 日
As illustrated above I don't see that problem with R2012b here using either numeric class; double or uint64.
Submit the sample code that produces the error to TMW as a bug report at www.mathworks.com
John BG
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
Jan 2016 年 2 月 27 日
What does
which diff -all
reply for uint64?
Walter Roberson
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
Paul 2018 年 3 月 14 日
Thanks Walter; an external toolbox rerouted the call to an external diff function with bad behavior. Deleting that function solved all problems. Sorry for the late reply.

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

 採用された回答

Paul
Paul 2018 年 3 月 14 日

0 投票

Problem solved; external diff function caused bad behavior; deleting this external function solved the problem.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2016 年 2 月 25 日

回答済み:

2018 年 3 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by