Asked by Iuliana Bledea
on 10 Jun 2019

I have this data from a mice experiment:

- Reaction Time
- Response Made (which can be 0,1 or 2)
- Visual contrast (one of 9 possible values)

I would like to use arrayfun to calculate the mean reaction time for each of the 9 values of visual contrast when the response made was 2.

Each set of data is written in a separate Matlab table.

Thank you.

Answer by Steven Lord
on 10 Jun 2019

Iuliana Bledea
on 10 Jun 2019

Iuliana Bledea
on 10 Jun 2019

Steven Lord
on 10 Jun 2019

Take a look at the "Multiple Grouping Variables" and "Multiple Grouping Vectors for Vector Input" examples on the documentation page to which I linked. You should be able to adapt these to your data.

Instead of computing the mean Weight for people grouped by Gender and whether or not they are Smokers, you could compute the mean ReactionTime for items grouped by Response and Contrast.

Sign in to comment.

Answer by the cyclist
on 12 Jun 2019

I believe that groupsummary is for data stored in tables only. You can do what you want with

[sortedResponses,~,idx] = unique(R(:,2));

meanTimes = accumarray(idx,R(:,1),[],@mean);

Here, R is your original data, and meanTimes will have the mean values for the sortedResponses.

You could also just do

mean(R(R(:,2)==2),1)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Iuliana Bledea (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713299

## the cyclist (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713300

## Iuliana Bledea (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713305

## Iuliana Bledea (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713310

## the cyclist (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713314

## Iuliana Bledea (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713318

## the cyclist (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713378

## Iuliana Bledea (view profile)

Direct link to this comment:https://es.mathworks.com/matlabcentral/answers/466319-i-need-some-help-with-arrayfun#comment_713381

Sign in to comment.