Hey, guys! I'm trying to get this program to recognize certain keywords in a sentence, and then based on those words, it will assign values to "a" and "b", and then multiply the two to give an answer.
Let me explain. If I write "helping your brother", the program should identify "Helping" as part of Good and then assign "a" a value of 1. it should also recognize "Brother" as part of Good and assign "b" a value of 1. At the end, the program should multiply these two numbers, and since a*b = 1, I should get something out of the pool of GoodResp[onses] like "that's good"
however, there's an error, and I'm boggled. "Any help here would be hot" thank you!
Error ————
??? Undefined function or method 'times' for input arguments of type 'cell'. Error in ==> goodbad2 at 29 prod = a.*b
———
Code:
GoodObject = {'brother', 'sister', 'mother', 'father', }; BadObject = {'killer','murderer', 'robber', 'thief'}; Bad = {'hurting', 'stealing', 'robbing', 'breaking'}; Good = {'helping', 'giving', 'caring'}; question = input('what? ','s'); if any(~cellfun(@isempty,regexpi(question,GoodObject))) a = 1;else if any(~cellfun(@isempty,regexpi(question,BadObject))) a = -1; else if any(~cellfun(@isempty,regexpi(question,Good))) b = 1; else if any(~cellfun(@isempty,regexpi(question,GoodObject))) b = -1; end end endend result = a*b BadResp = {'that''s bad', 'that''s very not good', 'that''s pretty bad'}; GoodResp = {'that''s very good', 'yep, that''s good', 'that''s good'}; OutBad = BadResp(randi(numel(BadResp))); OutGood = GoodResp(randi(numel(GoodResp))); if result == -1 disp(OutBad) else if result == 1 disp(OutGood) endend
Best Answer