Kreuzade
Kreuzade

Reputation: 777

Matlab 2-D sorting

I have a Matlab script which records a person speaking a phone number then finds where each number is spoken. Basically, I have the index within the main file where a smaller file is spoken; sometimes the smaller file can be found twice.

I have the indexes all the locations of '0', say they are 200 and 350. Now I find the indexes of '1', say 100 and 250. How can I reconstruct the phone number based on these indexes? The final answer should be '1010'. Can I have an array of tuples or something like:

x(1)=(200,0)
x(2)=(350,0)
x(3)=(100,1)
x(4)=(250,1)

Then sort them by their first element? If that is possible, I do not know the correct syntax. I hope this makes sense. Any help?

Upvotes: 1

Views: 45

Answers (1)

Chris
Chris

Reputation: 1531

Store X as a matrix like this:

 X=[ [200 0]
 [350 0]
 [100 1]
 [250 1]]

Then sort it via sortrows

>>sortrows(X)

ans =

   100     1
   200     0
   250     1
   350     0

Upvotes: 2

Related Questions