how do I subtract and then mean in every row of a data set?

1 view (last 30 days)
Say I had a 10000x10 matrix, and in every row. I wanted to take the conditional mean for columns 1-5 and 6-10, get the difference of these two means, and then make that appear in a new data set in the corresponding row. Would I use for loop? I am new to mat lab so I'm not sure how to use it Thank you
  4 Comments
Clifford Wu
Clifford Wu on 23 Apr 2015
Edited: Clifford Wu on 23 Apr 2015
The conditional mean for columns 1-5 means i take the probabilities used to generate columns 1-5, multiply them by 1-5, and then add them up, for example if p=[.1 .1 .1 .1 .1 .1 .1 .1 .1 .1] i would get (1*.1+2*.1...+5*.1)+(1*.1+2*.1...+5*.1)
Clifford Wu
Clifford Wu on 23 Apr 2015
Image Analyst - the dataset was a random distribution with probabilities for 10 binomials, it went something like mnrnd(7866,p,10000) I'd like the difference of the means to appear in a new data set, optimally, so I could just do mean(newdataset) in the end...

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 22 Apr 2015
v=rand(10,10); % Example
out=mean(v(:,1:5),2)-mean(v(:,6:10),2)

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!