To choose a random text in MATLAB, you need to have a cell array of text strings. Here’s an example:
main.m50 chars2 lines
Now, to choose a random text from this list, you can use the randi()
function to generate a random index within the range of the cell array and use it to access a text string at that position like this:
main.m81 chars4 lines
This will print a random text to the console. You can modify the range of randi()
function to choose a random text from a particular range only.
main.m68 chars4 lines
This modification will always print a random text from {'world', 'how', 'are'}
.
gistlibby LogSnag