MATLAB: What is the value of mean in this conditional argument

matlab functionmean

I have a matrix and a 1 column array:
a = [1;1;1;1;0;1;0]
b = [2 3 1 4 5;1 1 1 1 1;3 5 4 2 1;3 5 2 1 1;0 4 5 3 2;1 1 2 2 3;7 8 4 3 2]
and I do this command:
w = bsxfun(@times, b, mean(b(a==0,:)))
What are values in the matrix `w` a result of?
If I only had one 0 in a then all elements of b get multiplied by the mean of the row of b that was the same row number as the zero in a but what happens when now there are multiple zeros in a?

Best Answer

It multiplies ‘b’ by the mean of all the columns of ‘b’ calculating the column-wise mean of the rows of ‘b’ where ‘a’ equals 0.
It expands the shorter array to do element-wise multiplication.