Is there a way to find the mean of every other number in a vector and compare it to every other number in another vector?

1 vue (au cours des 30 derniers jours)
I'm working on a project where we are recording reaction times to flashing colored red and blue squares. We show each one twice, so red/blue/red/blue and a person has to press the spacebar when they see the square. We end up with something like:
red = [2 4 3 1 2 3 4 4 3 3]
blue = [2 3 2 2 1 1 2 3 2 4]
So the 1st and 3rd value, 2nd and 4th, etc of red I'd like to find the mean and then plot it against the blue's 1st and 3rd, 2nd and 4th, etc to see if red is faster than blue.
I was thinking of doing
xperson1= [red,1,3]
xperson2=[red,2,4]
x1mean=mean(xperson1)..
but xperson1 keeps ending up as a 1x12 double instead. Do I need to write a for loop for this? What syntax should I be using?
Thank you.

Réponses (1)

Jon
Jon le 23 Nov 2021
I'm not sure if I am clear on what you are trying to do but from your description I would do something like this:
red = [2 4 3 1 2 3 4 4 3 3]
blue = [2 3 2 2 1 1 2 3 2 4]
redMean = (red(1:end-2) + red(3:end))/2
blueMean =(blue(1:end-2) + blue(3:end))/2
plot(redMean,blueMean,'o')
xlabel('red mean')
ylabel('blue mean')
  2 commentaires
Kristin Aldridge
Kristin Aldridge le 23 Nov 2021
So using my real data
blue = [0.290566073000000 0.301381521000000 0.471992764000000 0.422390019000000 0.346596947000000 0.318810550000000]
red = [0.382376714000000 0.261531050000000 0.340653885000000 0.395819844000000 0.411721350000000 0.418958509000000]
So for this I tested 3 subjects, and each subject had their reaction time recorded twice.
Subject 1: blue = 0.290566073000000 0.301381521000000
red = 0.382376714000000 0.261531050000000
Subject 2: blue = 0.471992764000000 0.422390019000000
red = 0.340653885000000 0.395819844000000
Subject 3: blue = 0.346596947000000 0.318810550000000
red = 0.411721350000000 0.418958509000000
So they're all being saved in a vector, and I'd like to find the mean of each person's reaction time which requires me to find every two variables' mean. I'm not sure how to designate that.
Jon
Jon le 24 Nov 2021
Modifié(e) : Jon le 24 Nov 2021
Your example is very helpful. I think I understand better. I would do it like this:
% Assign test parameters
numFlashes = 2; % number of flashes of a given color shown to each subject
% Assign original data vectors
blue = [0.290566073000000 0.301381521000000 0.471992764000000 0.422390019000000 0.346596947000000 0.318810550000000]
red = [0.382376714000000 0.261531050000000 0.340653885000000 0.395819844000000 0.411721350000000 0.418958509000000]
% Find the number of subjects
% assume number of elements in blue and red are the same
% (could check this to make code more bullet proof)
numSubjects = numel(blue)/numFlashes;
% Put data into 2 dimensional arrays where each column has all the data for the subject,
% and each row has the reaction time for a flash (in your case two
% rows)
B = reshape(blue,numFlashes,numSubjects)
R = reshape(red,numFlashes,numSubjects)
% Compute column means for each subject
Bmean = mean(B)
Rmean = mean(R)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by