フィルターのクリア

Result of strfind

9 ビュー (過去 30 日間)
Mtlb Usr
Mtlb Usr 2011 年 2 月 7 日
Hi,
I'm using strfind function and I want to check the result of this function. However, when strfind doesn't find the string that I indicated and the result is {[]}, instead of the position value. I have tested the result of strfind with strcmp and == or ~= but I can't control the value.
How can I know whether value of strfind is {[]}?
Regards

採用された回答

Paulo Silva
Paulo Silva 2011 年 2 月 7 日
a={[]}
isempty(a{:}) %1 if a is empty, 0 otherwise
another option
numel(a{:}) %0 if a is empty, it returns the number of elements of a
  3 件のコメント
Paulo Silva
Paulo Silva 2011 年 2 月 7 日
thanks for pointing that out
Mtlb Usr
Mtlb Usr 2011 年 2 月 7 日
Hi Paulo,
I solved the issue, with your answer.
Thank you
regards

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

その他の回答 (1 件)

Oleg Komarov
Oleg Komarov 2011 年 2 月 7 日
I'll show an example:
% Example input
c = {'fine';'How are you'};
out = strfind(c,'fine')
out =
[1]
[]
% Return the index with exmpty cells
idxEmpty = cellfun('isempty',out)
idxEmpty =
0
1
% Positions on non empty results
posNonEmpty = find(~idxEmpty)
posNonEmpty =
1
% Extract non empty
c(~idxEmpty) % or c(posNonEmpty)
ans =
'fine'
Oleg

カテゴリ

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