Here's an example code that reads a string input from user, generates a random response based on the given table, and prints the response to the screen:
main.m394 chars12 lines
In this code, we first define the possible responses as a cell array. The input
function is used to read a string input from the user. Then, we use the randi
function to generate a random index for the responses
array. Finally, we use fprintf
to print the randomly selected response to the screen.
Note that in order to run this code multiple times and generate different responses each time, you should call the rng
function at the beginning of your code to set the random number generator's seed to a different value each time.
gistlibby LogSnag