unique() function not working in external mode

조회 수: 8 (최근 30일)
Dr. Mark
Dr. Mark 2017년 9월 6일
댓글: Stephen23 2017년 9월 7일
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
Dr. Mark
Dr. Mark 2017년 9월 6일
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...

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2017년 9월 6일
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
Dr. Mark
Dr. Mark 2017년 9월 6일
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 2017년 9월 7일
@Dr. Mark: please upload the values in a .mat file.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by