Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
bartekltg

Posts: 32
Registered: 12/11/12
Re: lookup cell array for string and take corresponding value
Posted: Dec 13, 2012 4:20 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.