Reputation: 145
I'm trying to use the Simulink sort block (ascending) in index mode to allow me to determine the order of my signals.
I've tested it with four constants but it just doesn't seem to work. Is there something obvious that I'm missing? I think the order (in Display 4) should be 3. 2 4 1
Here's a picture:
Upvotes: 1
Views: 764
Reputation: 36710
I will answer this first in MATLAB code because the code is easier to reproduce and understand, a Simulink version below. Further I multiplied all values with 10 to clearly distinguish between indices and values. Sort returns the indices, which are required to sort the list, the same the MATLAB sort function does:
>> x=x.*10
x =
30 20 40 10
>> [~,idx]=sort(x)
idx =
4 2 1 3
>> y=x(idx)
ans =
10 20 30 40
What you expect is the inverted permutation which which can be used to create the original list:
>> idx2(idx)=1:4
idx2 =
3 2 4 1
>> y(idx2)
ans =
30 20 40 10
Finally the Simulink version:
Upvotes: 2