Hi Mike,

Thank you for all the great videos! I’m trying your suggested exercise from “Complete Neural Signal Processing and Analysis: Zero to Hero” 185: Phase synchronization matrices in multitrial

data at about 12:30 where you suggest to take away the 2 **for** loops and use **bsxfun** instead. I’m having quite a bit of trouble with it and was wondering if you may have more input on the matter.

I have two 3D matrices that are the same.

size(**A**) = [10 100 50]

size(**B**) = [10 100 50]

I want to subtract along every value in the 1st dim of **A** with every value in 1st dim of **B** with no **for** loops so using **bsxfun**. I will also take the mean in the middle

I want to end up with 10x10x50. How do I do this?

So far, I just have

**z = mean(bsxfun(@minus, A, B, 2)**

which subtracts every matching data index in 1st dim so [1-1] [2-2] … [10-10]

I’m left with a 10x1x50 matrix of zeros.

I want to subtract along the 1st dim of **A** and **B**

| [1-1] [1-2] … [1-10]

| [2-1] …

| …

V [10-1] [10-2] … [10-10]

Matrix **A**…Matrix **B** - - ->

I can do this for loop and I get the 10x10x50 matrix I want:

for i = 1:10

for j = 1:10

z = mean(bsxfun(@minus, **A**(i), **B**(j), 2)

end

end

How would you do this without for loops?