How to write a code to estimate parity of numbers in a sequence?

4 次查看(过去 30 天)
Hi all,
I am trying to write a code that would give me an accuracy value (correct = 1, incorrect = 0).
In the matrix below first column represents a sequence of numbers presented to study participants and column two - task response (a key press - 1(same), 2(different), 0(no response). A judgement is made about the parity of each number in the first column (starting from the third number in the sequence) of whether the parity of this number is the same or different as the parity of the number two numbers back. For example, - is the parity of 5 same or different as 8? - the correct response would be 2 - different. In the case below the response was 1, which is incorrect, in which case I would need an output of 0 here. Next, - is the parity of 3 same or different as 0? - correct response again would be different (2) - output - 0. I would need a code that runs through the matrix in such manner.
Any suggestions on what code would do the job? Even a half solution or a hint will be appreciated.
5 0
0 0
8 1
3 0
9 0
2 0
7 0
6 0
1 0
4 2
8 0
1 2
0 2
5 0
9 0
7 0
2 0
6 0
3 0
4 0

采纳的回答

Ridwan Alam
Ridwan Alam 2019-12-19
bnumbers = [5 0 8 3 9 2 7 6 1 4 8 1 0 5 9 7 2 6 3 4]';
bresponse = [0 0 1 0 0 0 0 0 0 2 0 2 2 0 0 0 0 0 0 0]';
bbinary = de2bi(bnumbers);
bparity = (mod(sum(bbinary,2),2)~=0); % even parity
bcorr_resp = [0;0;abs(bparity(3:end)-bparity(1:end-2))+1];
baccuracy = (bresponse==bcorr_resp);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by