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

조회 수: 2 (최근 30일)
Tracey Rochester
Tracey Rochester 2020년 1월 18일
댓글: TADA 2020년 1월 19일
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
Tracey Rochester
Tracey Rochester 2020년 1월 19일
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 2020년 1월 19일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by