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

2 ビュー (過去 30 日間)
Agnese Usacka
Agnese Usacka 2019 年 12 月 19 日
コメント済み: Agnese Usacka 2019 年 12 月 31 日
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);
  1 件のコメント
Agnese Usacka
Agnese Usacka 2019 年 12 月 31 日
Thank you ever so much for the code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by