Random Sampling of Cell Array Variables which are not necessarily numeric

3 vues (au cours des 30 derniers jours)
Welbeck  Sintim
Welbeck Sintim le 14 Jan 2020
Commenté : Stephen23 le 14 Jan 2020
Hello guys.
I have a multiple choice question that I want to generate several different responses or answers for in Matlab, but I am very new with Matlab and don't know how to go about it.
For example. I can put the answers to the question in a cell array such as:
>> Answer = {'a' 'b' 'c' 'd'};
But I don't know how to randomly sample or select an answer from this Cell array. I tried to use rand() but it didn't work because it is only for numeric variables.
Is there anything like that for characters or string variables in Matlab?
I want to generate multiple responses so I can find out how much times a particular choice was made, then use that to create a frequency table or some sort of data analysis.

Réponses (1)

Bhaskar R
Bhaskar R le 14 Jan 2020
Modifié(e) : Bhaskar R le 14 Jan 2020
result = Answer{randi([1, 4])};

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by