Effacer les filtres
Effacer les filtres

Can anyone please explain me this line of a code?

1 vue (au cours des 30 derniers jours)
jasmine
jasmine le 7 Juin 2019
Commenté : jasmine le 7 Juin 2019
probability = arrayfun(@(x) mean(audR(audR(:,1)==x,2)==2) , contrast);
  5 commentaires
Adam Danz
Adam Danz le 7 Juin 2019
Modifié(e) : Adam Danz le 7 Juin 2019
Ahhh... yeah it's an array (blush).
audR(:,1)==x %this produces a logical index marking rows of the first
%column of audR that match the input value 'x'
audR(audR(:,1)==x,2) % for each of those rows from the comment above,
% you're extracting the data from the second
% column of audR.
(audR(audR(:,1)==x,2)==2) %and finally, you're determining whether those
% values are equal to 2.
Here's an example you can execute line by line to see what's going
% Produce fake data
audR = [[1;1;2;2;3;3],[1;2;1;2;1;2]];
x = 2
audR(:,1)==x
audR(audR(:,1)==x,2)
(audR(audR(:,1)==x,2)==2)
jasmine
jasmine le 7 Juin 2019
Thank you very much for your answer!

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 7 Juin 2019
Modifié(e) : Stephen23 le 7 Juin 2019
If audR is a matrix, then
audR(audR(:,1)==x,2)==2
% ^^^^^^^^^ % first column of audR
% ^^^ % ... is equal to x.
% ^^^^^^^^^^^^ % used as a logical index into the rows of audR
% ^ % second column of audR
% ^^^ % ... is equal to 2.
So the code takes the rows of audR where the first column equals x, and checks if their second column equals 2.
  1 commentaire
Adam Danz
Adam Danz le 7 Juin 2019
+1 for simple and effective explanation

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by