How do I find the mean of a binary set for each value of no.1 to7

2 views (last 30 days)
I have a vector row of 5,000 random no.s 1 to 7. I have a vector row of 5,000 1's and 0's as a second vector row. (This represents 5,000 tirials, where every time the random number was > 4, the machine chose 1, otherwise 0). I have put both vectors together in a matrix/array with the values on top row and the binaries on the second row. I have to calcualte the mean of the responses for each of the values. How do I do this please? I am beginner level and need my variables spelled out, to understand them. I think I use accumarray and mean but not sure how to compile the coding.
  3 Comments
Tracey Rochester
Tracey Rochester on 19 Jan 2020
Thank you so much – your code is so clearly described! I too thought the Q rather ridiculous, given the perfect scores, however I think we have to find the mean because we are going to add human error in a future task, for which I will have to adopt the same principle. I'm going to work through this now... thanks again!! Not quite sure how 'double' generates a 1, and Matlab help is as clear as mud on it, but will play around with it a bit.
P.S. My way of creating what you have was much more long-winded with a for loop and if statement! But I guess as you get better at this, you quickly recognise simpler, more efficient ways :-)
comparisonStimulusValue = randi(7);
correct = [ ];
correctV = [ ];
comparisonStimulusValueV = [ ];
for iTrials = 1:5000; % Trial has 5,000 iterations...
comparisonStimulusValue(1) = randi(7);
if (comparisonStimulusValue > 4);
correct = 1;
correctV = [correctV correct];
comparisonStimulusValueV = [comparisonStimulusValueV comparisonStimulusValue];
correct = 0;
correctV = [correctV correct];
comparisonStimulusValueV = [comparisonStimulusValueV comparisonStimulusValue];
end
% End of conditional behaviours
end
% End of repeated loop
comparisonStimulusValuesAndResponsesM = [comparisonStimulusValueV; correctV];
TADA
TADA on 19 Jan 2020
how 'double' generates a 1
What image analyst did there was to generate a logical vector which determines when the value is greater than 4:
b = topRow > 4
b =
0 1 0 0 0 0 0 1 0 1
Next this binary vector was converted to an array of double precision numbers by sending it to the double function
bottomrow = double(b);
Or in a single line of code as image analyst did

Sign in to comment.

Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!