representing and empty cell

3 ビュー (過去 30 日間)
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi 2011 年 11 月 27 日
I have a problem in setting this right.
I have this struct,
wordstruct =
a: {'amal' 'asyik' 'ampun'}
b: {'bola' 'busuk' 'basi'}
c: {'cacing' 'campur' 'cucuk'}
.
.
.
z: {''..........''}
i want to compare an input of a string with a word in one of the fields in the struct so i tried this,I want to display that if the word does not exist, it'll say the word is invalid.
I know that if I have this line of code and the word does exist, it'll show me something like this,
word='bola'
(strfind(wordstruct.(word(1)),word);
ans =
[1] [] []
and if word='bell' %does not exist in struct
ans =
[] [] []
however im having difficulty to represent the empty cell in my if statement where i have it like this:
if (strfind(wordstruct.(word(1)),word)= %%%%IDK this part
fprintf('this word is invalid');
else
fprintf('%s is in the wordbank',word);
end
  1 件のコメント
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi 2011 年 11 月 27 日
or maybe anybody has a another suggestion of doing this?

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

採用された回答

per isakson
per isakson 2011 年 11 月 27 日
Does this help?
wordstruct.a = {'amal' 'asyik' 'ampun'};
wordstruct.b = {'bola' 'busuk' 'basi'};
wordstruct.c = {'cacing' 'campur' 'cucuk'};
word = 'bola';
if any( strcmp( word, wordstruct.('b') ) )
disp( 'found the word' )
else
disp( 'failed' )
end
  1 件のコメント
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi 2011 年 11 月 27 日
yes, this would definitely work!thank you very much!You've made my Sunday better!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by