Prev: Move 3d object with wiimote..
Next: bode plot
From: Rodrigo on 11 Jun 2010 22:49 Hello, I've been trying to come up with some code for finding a specific element adress of a given cell vector without looping through each element. For example, L = {'L','L','L','L','L1','L2','L','L'}'; r = someFcn(L); I want the position of L2, like r=6 (line 6 and colun 1). I am trying to find if there is a Matlab function that does this, or if I need to write my own. Thanks
From: Walter Roberson on 12 Jun 2010 00:42 Rodrigo wrote: > I've been trying to come up with some code for finding a specific > element adress of a given cell vector without looping through each > element. For example, > > L = {'L','L','L','L','L1','L2','L','L'}'; > r = someFcn(L); > > I want the position of L2, like r=6 (line 6 and colun 1). I am trying > to find if there is a Matlab function that does this, or if I need to > write my own. [tf, r] = ismember('L2', L);
From: Rodrigo on 14 Jun 2010 11:50 "Rodrigo " <rodrigoandriolo(a)hotmail.com> wrote in message <huusj1$6r4$1(a)fred.mathworks.com>... > Hello, > > I've been trying to come up with some code for finding a specific element adress of a given cell vector without looping through each element. For example, > > L = {'L','L','L','L','L1','L2','L','L'}'; > r = someFcn(L); > > I want the position of L2, like r=6 (line 6 and colun 1). I am trying to find if there is a Matlab function that does this, or if I need to write my own. > > Thanks Thank you, :D
From: Jan Simon on 14 Jun 2010 15:17 Dear Rodrigo! > L = {'L','L','L','L','L1','L2','L','L'}'; > r = someFcn(L); > > I want the position of L2, like r=6 (line 6 and colun 1). I am trying to find if there is a Matlab function that does this, or if I need to write my own. If the cell elements are strings, STRCMP is much faster than ISMEMBER: r = find(strcmp(L, 'L2')); If logical indexing can solve your problem, avoid the FIND to save further time, e.g. to remove these cell elements: L = {'L','L','L','L','L1','L2','L','L'}'; L(strcmp(L, 'L2')) = [] Good luck, Jan
|
Pages: 1 Prev: Move 3d object with wiimote.. Next: bode plot |