unique() returns duplicate values in the beginning of the array
Show older comments
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.
Answers (1)
Star Strider
on 14 Jun 2016
0 votes
They’re actually not both zero.
4 Comments
Walter Roberson
on 14 Jun 2016
And use
format long g
so you can see the entire value.
Star Strider
on 14 Jun 2016
Thank you, Walter!
I overlooked that.
Jenny Shu
on 14 Jun 2016
Walter Roberson
on 14 Jun 2016
>> 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
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!