フィルターのクリア

Usage of strcmpi in embedded strings

1 回表示 (過去 30 日間)
T
T 2014 年 1 月 15 日
コメント済み: T 2014 年 1 月 16 日
suppose you have the following:
A = 'filename.exe'
B.B =
'whatisthatman.exe'
'nevermind.txt'
'ok.exe'
'\nevermind\filename.exe'
Is it possible to get the index of filename.exe that's embedded in that string with strcmpi?
  3 件のコメント
Walter Roberson
Walter Roberson 2014 年 1 月 16 日
The outer B could be a structure array with 4 entries; then the output would be structure array expansion.
T
T 2014 年 1 月 16 日
Yes.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 1 月 16 日
No, strcmpi() always compares entire strings. "filename.exe" does not occur as the entire string in the 4th entry in B.B, so strcmpi() is not suitable. You will need to use regexp() or strfind()
Are you looking for the index within B(4).B, which would be 12, or are you looking for the index of the entry that contains the string, which would be the 4 ?
cellfun( @(S) ~isempty(strfind(A, S)), {B.B} )
would return [false false false true]
  7 件のコメント
Walter Roberson
Walter Roberson 2014 年 1 月 16 日
Bfixed = {B.B};
Bfixed(isnan(Bfixed)) = {''};
T = regexp( Bfixed, ['.*' A '.*'], 'match' );
vertcat(T{:})
T
T 2014 年 1 月 16 日
Bfixed(isnan(Bfixed))
Undefined function 'isnan' for input arguments of type 'cell'.

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

カテゴリ

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