-1

I'm a newbie to Matlab and have a question about str locating:

A = ['abc','de','fghij','something','another'];

Then how can I get 3 if I use strfind(A,'fghij')?

Thanks.

newbieSOF
  • 67
  • 1
  • 7
  • After converting `A` to a [cell array](http://www.mathworks.com/help/matlab/matlab_prog/cell-arrays-of-strings.html) (due to the semantics of [strings in Matlab](http://www.mathworks.com/help/matlab/matlab_prog/creating-character-arrays.html), I'd suggest the [second highest answer](http://stackoverflow.com/a/18649852/3121310) with `strcmp` since it is fastest. – TroyHaskin Mar 28 '16 at 02:59

2 Answers2

0

I'm not exactly sure I understand your question, but if you are wondering why the value is 3 instead of 2 it is because matlab (unlike most languages you may be used to) indexes arrays starting at 1 instead of 0.

Josh Wilson
  • 3,585
  • 7
  • 32
  • 53
  • oh...I know Matlab is different with C/Java in indexing. My question is how to find the index. Since Mablab uses cells of strings, and I'm not quite familiar with such "data structures", I cannot figure how to locate a string....still thank you~ – newbieSOF Mar 28 '16 at 02:57
0

Thanks @TroyHaskin ! I find the answer in another post~

idx=find(ismemeber(A,'fghij')) is what I want.

newbieSOF
  • 67
  • 1
  • 7
  • 1
    If the duplicate answered your question, you should select the "That solved my problem!" button at the top of your question in the duplicate dialogue. – TroyHaskin Mar 28 '16 at 03:05