unique() returns duplicate values in the beginning of the array

I ran this line
struct1.points = unique([0:.00001:struct2.highbound struct2.highbound])';
then I opened struct1.points and I saw the first two elements are both 0. I tried to copy the two elements and paste outside Matlab to see if they're strict 0s and the answer is yes -- both are exactly equal to 0. The array looks like this:
0
0
2.00000000000000e-05
3.00000000000000e-05
4.00000000000000e-05
5.00000000000000e-05
5.99999999999999e-05
7.00000000000000e-05
But theoretically the second element should be 1.0000e-05 and there should not be duplicate values. Why is that not the case? Any thoughts appreciated.Thanks.

Réponses (1)

Star Strider
Star Strider le 14 Juin 2016
They’re actually not both zero.

4 commentaires

And use
format long g
so you can see the entire value.
Thank you, Walter!
I overlooked that.
No they're both 0. I copied these two numbers and pasted outside Matlab. There's no digits after the 0.
>> format long g
>> struct2.highbound = (pi/1000);struct1.points = unique([0:.00001:struct2.highbound struct2.highbound])';
>> size(struct1.points)
ans =
316 1
>> struct1.points(1:10)
ans =
0
1e-05
2e-05
3e-05
4e-05
5e-05
6e-05
7e-05
8e-05
9e-05

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange

Question posée :

le 14 Juin 2016

Commenté :

le 14 Juin 2016

Community Treasure Hunt

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

Start Hunting!

Translated by