Unique function doesn't work in Simulink

조회 수: 10 (최근 30일)
Andrew Poissant
Andrew Poissant 2017년 9월 22일
댓글: Andrew Poissant 2017년 9월 25일
I have a 624x2 matrix that needs to have repeated ordered pairs removed. The first column represents x values and the 2nd column represents y values. There are some repeating pairs and I need to remove them in the matlab function block in Simulink but when I execute the "unique" function in Simulink I get an error saying: An error occurred while running the simulation and the simulation was terminated Caused by: The second operand is not sorted in ascending order. Use SORT first.
How do I get around this error? If I use "sort" then won't I lose my ordered pairs because the two columns will be sorted independently? My highly simplified code is below.
SRM = some 624x2 matrix SRM = unique(SRM(:,:), 'rows');
  댓글 수: 2
OCDER
OCDER 2017년 9월 22일
That's odd, since unique(SRM, 'rows') should remove duplicate rows and sort for you.
If you need to sort by rows, use sortrows .
Andrew Poissant
Andrew Poissant 2017년 9월 25일
Sortrows works well but for some reason simulink is still giving the same error even when I sort by rows. It seems like a really rigid addition to matlab. Any idea how to remove repeated rows without unique?

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

답변 (1개)

Brian Hannan
Brian Hannan 2017년 9월 25일
You can use the 'stable' setOrder argument to get around this.
  댓글 수: 1
Andrew Poissant
Andrew Poissant 2017년 9월 25일
I tried this, but am still getting the same error requesting that I use SORT first. I am getting an error using the following line: SRM = unique(SRM(:,1:2), 'rows', 'stable');

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by