Problem Multiplying- mtimes doesn't work for cells
Show older comments
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
end
end
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)
end
end
1 Comment
per isakson
on 27 Jun 2013
Edited: per isakson
on 27 Jun 2013
Insert the line
a, b
above
prod = a.*b;
and tell us what it shows.
BTW: should be elseif in one word
Accepted Answer
More Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!