display multiple text in seperate then choose from random in matlab

You can use a cell array to store multiple text strings and then use the datasample function to randomly select one of them. Here's an example:

main.m
% Define the text strings
text = {'Hello', 'Hi', 'Hey', 'Greetings'};

% Use datasample to select a random one
selected_text = datasample(text, 1);

% Display the selected text
disp(selected_text)
197 chars
9 lines

Each text string is enclosed in single quotes and separated from the others using commas. The datasample function takes two arguments: the first is the array of data to sample from (in this case, text) and the second is the number of samples to select (in this case, just 1).

Executing this code multiple times will display different random text each time.

Hope this helps!

related categories

gistlibby LogSnag