unique() function not working in external mode
8 views (last 30 days)
Show older comments
I am using Simulink real-time on a target computer. I have a piece of code that seems like it should work, and works when I run it locally, but it doesn't work on the target.
coder.varsize('uniqueRows',[100 3])
uniqueRows = unique([V1,V2,V3],'rows');
where V1, V2, and V3 are constant parameters and are always column vectors of doubles of size [100,1]. It always thinks all 100 of 100 rows are unique, when they are actually not. Any ideas?
Answers (1)
Guillaume
on 6 Sep 2017
I found the cause of the problem: unique() can't tell that two zeros are the same
More likely, your two zeros are not the same and slightly different from zero (at least one of them) but also much smaller than eps(1). Then when you add eps(1) to your not-exactly-zero that small difference gets cancelled by the massive increase in magnitude.
e.g:
v = [1e-307, 1e-306]
unique(v) %values are not equal
unique(v+eps) %values are equal because the minute difference gets cancelled by the massive increase in value
2 Comments
See Also
Categories
Find more on Target Computer Setup 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!