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

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

"conditional mean for columns 1-5" &nbsp I'm not sure I understand what that is.
What do you mean by "data set", and if you mean just regular numbers, then where in the 10,000 by 10 matrix do you want the difference of the two means to appear? In column 11? In column 10,001?
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)
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

v=rand(10,10); % Example
out=mean(v(:,1:5),2)-mean(v(:,6:10),2)

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!