Trying to use a while loop to create experimental conditions?

2 vues (au cours des 30 derniers jours)
Chris Keightley
Chris Keightley le 2 Mai 2021
Hello everyone,
I am ultra new to Matlab. I am trying to create a Psychology experiment that requires 6 different random combinations of "target present" and "target absent". Thus I am using 1's to represent "target present" and 2's to represent "target absent". I am trying to use the following code to execute the function "randi(2,20,1)" 6 times by using a while loop to fill in the matrix T (column by column). However, I cannot figure out how to get the code right. Any help would be appreciated.
Thanks so much,
T = [(zeros(20,1))]
ii=1
while ii < 6
ii = ii+1
T(ii,1) = randi(2,20,1)
end

Réponse acceptée

David Fletcher
David Fletcher le 2 Mai 2021
Modifié(e) : David Fletcher le 2 Mai 2021
Is this what you are after?
ii=1
while ii <= 6
T(ii,:) = randi(2,1,6);
ii = ii+1;
end
T =
1 1 2 1 2 1
2 1 1 1 2 1
1 2 2 2 2 1
2 2 1 2 1 1
2 2 2 1 2 1
1 1 1 2 1 2

Plus de réponses (0)

Catégories

En savoir plus sur Psychology 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