フィルターのクリア

Need vectorized strfind command

5 ビュー (過去 30 日間)
Noel
Noel 2012 年 1 月 20 日
If constname is 146x4 char array (column vector of 146 4-character strings, I need the following command to return the index number of the string 'M12 '. But it doesn't. strfind doesn't work with arrays of strings. Which command does? My only option right now is a for loop and the strcmp command, which works, but, hey, this is Matlab!
index = strfind(constname,'M12 ')

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 1 月 20 日
Convert your 146x4 char array to a 146x1 cell array and then use strfind:
A = repmat('friday',146,1);
B = num2cell(A,2);
strfind(B,'fri')
  2 件のコメント
Noel
Noel 2012 年 1 月 20 日
Thanks, Sean. Fantastic resource. First time i used it!
The following works for me:
B = num2cell(constname,2)
[dex, bol] = find(strcmp(B,'M12 '))
Now my quibble. The docs say nothing about num2cell converting character strings to cells ala str2cell.
But thanks. It's done!
Sean de Wolski
Sean de Wolski 2012 年 1 月 20 日
Great!
Please accept this answer, to mark the question closed.
It does say num2cell takes any type of array.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by