すべてが'else'になる

14 views (last 30 days)
Huge Grave
Huge Grave on 22 Apr 2021
Commented: Hernia Baby on 22 Apr 2021
現在、if文を使用して条件づけを行い、分岐させています。
しかし、どの条件でもelseの分岐'偽'になってしまいます。
試しに、if-else-endを消して実行すると'真'に分岐します。
こうした時、何が原因となっているのでしょうか
%moziは22×1のcell
%辞書の読み込み
jisho = readtable('dictionary.xlsx','ReadRowNames',true);
Chushutumoji=moji{1,1};
%条件分岐
if sum(categorical(true) == Chushutumoji)
Shoukai = jisho(Chushutumoji,:);
disp(Shoukai)
else
disp('False')
end

Accepted Answer

Hernia Baby
Hernia Baby on 22 Apr 2021
エクセルデータがないので何とも言えませんが、おそらく条件文が誤っています。
sum(categorical(true) == Chushutumoji)
ですが
Chushutumojiが 'true' という文字でない場合、elseを返しています。
Chushutumojiが仮に調べたい単語 'Hernia' 等の場合、偽になり 'False' が返されます。
  1 Comment
Hernia Baby
Hernia Baby on 22 Apr 2021
trueが何かの変数の場合はその限りではありません

Sign in to comment.

More Answers (0)

Categories

Find more on table in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!