string - Matlab - Find index of a cell by its value -



string - Matlab - Find index of a cell by its value -

i have cell array filednames 11x1 in each cell single string , want index of cell equal string name.

i've found example:

c = { {'a'}, {'b'}, {'c'}, {'a'}, {'a'} } % info idx = find(strcmp([c{:}], 'a')) % single line engine

however when apply case:

find(strcmp([fieldnames{:}], 'b_h_epsq_h'))

nothing happens, , strcmp([fieldnames{:}], 'b_h_epsq_h') , doesn't find match, although if type strcmp([fieldnames{2}], 'b_h_epsq_h') reply 1.

i tied transpose cell array illustration 1x5 still no success

use following:

idx = strcmp(fieldnames, 'b_h_epsq_h') find(idx) example: >> fieldnames = {'a', 'b', 'c', 'd', 'e'}; >> idx = strcmp(fieldnames, 'c') idx = 0 0 1 0 0 >> find(idx) ans = 3

string matlab strcmp cell-array

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -