Dang Khoa
Dang Khoa

Reputation: 5823

Building a matrix of indices

(First, the title is REALLY vague - but I can't think of a way to better ask my question. Please feel free to edit the title, then delete this note.)

Suppose I have a matrix ref:

>> ref
ref = 40 20 90 30

And I have a matrix permuted:

>> permuted
permuted = 20 40 30 90

Is there an operation that produces a matrix idx such that isequal(ref, permuted(idx))? In this case, idx == [2 1 4 3].

Upvotes: 1

Views: 74

Answers (1)

Eitan T
Eitan T

Reputation: 32920

What you need is ismember:

[tf, idx] = ismember(ref, permuted);

For your example this would indeed yield:

idx =
    2     1     4     3

Upvotes: 4

Related Questions