unique() function not working in external mode

8 visualizzazioni (ultimi 30 giorni)
Dr. Mark
Dr. Mark il 6 Set 2017
Commentato: Stephen23 il 7 Set 2017
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?
  1 Commento
Dr. Mark
Dr. Mark il 6 Set 2017
I found the cause of the problem: unique() can't tell that two zeros are the same when running on the target. This fixed it:
uniqueRows = unique([V1,V2,V3]+eps,'rows');
But this issue is not mentioned anywhere in the documentation...

Accedi per commentare.

Risposte (1)

Guillaume
Guillaume il 6 Set 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 Commenti
Dr. Mark
Dr. Mark il 6 Set 2017
That makes sense, but they are parameters that I enter, and always have integer values. I even tried to floor() them before calling unique, which did not solve the problem.
Stephen23
Stephen23 il 7 Set 2017
@Dr. Mark: please upload the values in a .mat file.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by