Creating a randomly generated sentence in MATLAB

15 Ansichten (letzte 30 Tage)
Michael Doherty
Michael Doherty am 1 Okt. 2016
Beantwortet: Image Analyst am 1 Okt. 2016
So I'm relatively new to MATLAB and am having trouble creating a randomly generated sentence.
greet = {'Well hello,', 'Hi,', 'Good day,', 'Aloah'};
flatter = {'aren''t you looking beautiful today!', 'your hair looks awesome!', 'you have beautiful eyes!', 'have you been working out?'};
bye = {'Have a wonderful rest of your day!', 'Please do come back soon!', 'Take care!'};
I would like it to display as something along the lines of "Well hello, have you been working out? Take care!"
I tried using fprintf with all three as arguments, but to no avail. I feel as though I need to be using rand() somewhere in it, but not sure how to go about it.
Any suggestions? Thank you in advance!

Akzeptierte Antwort

James Tursa
James Tursa am 1 Okt. 2016
randi would be a natural choice here. E.g., for the pieces:
greet{randi(numel(greet))}
flatter{randi(numel(flatter))}
bye{randi(numel(bye))}

Weitere Antworten (1)

Image Analyst
Image Analyst am 1 Okt. 2016
Here's another way to generate a randomly generated sentence:
>> why
Try it and see what you get.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by