Help with acquiring means of different columns using on one single matlab code

5 次查看(过去 30 天)
kklkj

采纳的回答

Giorgos Papakonstantinou
  • For the first question:
ismember(Gender, 'Male')
Will give a logical vector with true(1) the males and false(0) the females. With this logical vector you can index the columns which refer to the response times of the males.
ResponseTimes(:,ismember(Gender, 'Male'))
This will build the matrix with the response times of all males
Now you only have to take the mean in each column of the previous matrix
MeanResponseTimeofMales = mean(ResponseTimes(:,ismember(Gender, 'Male')))
  • For the second question:You have to build a logical matrix that will indicate which response times are above 2.5. Similarly you do this by:
ResponseTimes>2.5
The true values (1) will be the ones above 2.5 and the false values (0) will be the ones less or equal to 2.5.
Now simply you need to find if ANY of the columns have at least one true value. You do this by logical indexing:
any(ResponseTimes>2.5)
Now, since you know which columns have at least one true value you must use the previous logical vector to index your Name cell.
Names(any(ResponseTimes>2.5))
but read about logical indexing, ismember and any. And as Walter said, spend some time reading the how-to-ask-questions tutorial

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by