Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: lookup cell array for string and take corresponding value
Replies: 1   Last Post: Dec 13, 2012 4:20 PM

 Messages: [ Previous | Next ]
 bartekltg Posts: 55 Registered: 12/11/12
Re: lookup cell array for string and take corresponding value
Posted: Dec 13, 2012 4:20 PM

W dniu 2012-12-13 22:06, Shashank Amburkar pisze:
> I've got a 2000x2 cell array that has strings in both columns. The
> strings in the first column go from A1 to A32 (but repeat so you may see
> A1, A2, A1, A1, A5....) and the strings in the 2nd column are either
> E,W,N,S and correspond to the one of the strings in the first column
> (and are always the same for a given first column string - A1 will
> always be E, A2 will always be W....). I want to build a 32X2 cell
> array that has A1 thru A32 on the first column with their corresponding
> 2nd column strings (E,W,N,S).

Use unique and extract indexes.

A = {'2','w';'3','e';'2','w';'1','n'}
[B,I,J]=unique(A(:,1));
B = A(I,:);
disp(B)

bartekltg

Date Subject Author
12/13/12 Shashank Amburkar
12/13/12 bartekltg