I need some help with arrayfun

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.

댓글 수: 8

jasmine
jasmine 2019년 6월 10일
편집: jasmine 2019년 6월 10일
This is how my data looks like.
First column - Reaction Time
Second column - Response Made
Third column - Visual contrast
the cyclist
the cyclist 2019년 6월 10일
Can you upload the data itself, or a small sample, instead of an image?
jasmine
jasmine 2019년 6월 10일
Attached is the data
jasmine
jasmine 2019년 6월 10일
편집: jasmine 2019년 6월 10일
the cyclist
the cyclist 2019년 6월 10일
Is the data already in MATLAB? Can you upload a MAT file?
The reason I suggest that is that (a) there are many ways to load data into MATLAB, which can give subtly different MATLAB variables, and (b) then we can test code directly on your data, to see if our algorithm works for you.
jasmine
jasmine 2019년 6월 10일
it is in MATLAB, but it is structured in a lot more complicated form and I think it won't be very helpful to update it like that
the cyclist
the cyclist 2019년 6월 10일
Well, the main information I am trying to get at is the data types and how you are storing.
You make the statement "Each set of data is written in a separate Matlab table". That suggests to me that you have three variables of data type table. But your screen shot shows three columns of a single variable of data type double.
I'm just trying to sort this out, so that I don't suggest a solution that doesn't actually work for how your variables are stored.
jasmine
jasmine 2019년 6월 10일
Sorry, yeah, they are normally stored as single double type.

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

답변 (2개)

Steven Lord
Steven Lord 2019년 6월 10일

0 개 추천

I don't think arrayfun is the tool you want to use here. Instead groupsummary seems like a better fit.

댓글 수: 3

jasmine
jasmine 2019년 6월 10일
I used arrayfun to calculate the probability to obtain a specific response (0, 1 or 2) for each of the 9 contrast values. But now that I had to deal with the reaction time as well, it got too complicated. Do you have any idea how I could use groupsummary for this?
jasmine
jasmine 2019년 6월 10일
Pressuming that the response made is always = 2 (also making it a bit easier this way), how can I get the mean reaction time for each of the 9 visual contrasts?
Steven Lord
Steven Lord 2019년 6월 10일
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.

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

the cyclist
the cyclist 2019년 6월 12일

0 개 추천

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)

태그

질문:

2019년 6월 10일

답변:

2019년 6월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by