## How can I subtracting the members of a 3D Matrix ?

### mr mo (view profile)

on 4 Dec 2016
Latest activity Edited by mr mo

### mr mo (view profile)

on 8 Dec 2016
Hello every one. I have a 3D matrix of size
every member of this matrix is a random number between 1 to 5 like
from
I want to subtract each members of matrix A from the 9 overlaying members of it.
but my question is how can i do this procedure for the members that have 4, 5 or 6 overlaying members.
for example member of index (i,j,k)=(1,1,2) that has only 4 overlaying members in z=1 and this code is not useful in this situation because this code working in cases that there are only 9 overlaying members.
In fact for
(i,j,k)=(:,1,2)
and
(i,j,k)=(:,end,2)
and
(i,j,k)=(1,:,2)
and
(i,j,k)=(end,:,2)
in all pages from z=2 to z=10 this code is not useful and I am very confused because these members have 4 or 6 overlaying members . with best regards.

### Image Analyst (view profile)

on 5 Dec 2016

Use convn() with the proper kernel. But I'm not really sure what you mean by overlaying members and what's going on with the z=1 plane.

Show 1 older comment
Image Analyst

### Image Analyst (view profile)

on 5 Dec 2016
OK, so you have a 10*10*10 3D matrix with 1000 elements in it.
You say " I want to subtracting the members of the 3D Matrix from" <== OK that means you want to subtract 1000 elements from something.
Then you say "from 9 overlaying member which is above it" OK, this means that you want to subtract 1000 elements from 9 elements. You can only subtract the same number of elements or a single elements. So you can subtract 1000 numbers from the corresponding 1000 numbers or you can subtract 9 numbers from 9 numbers, OR you can subtract 1 number from all 1000 elements, or subtract 1 number from 9 elements. I'm not sure what you want to do. But I know you can't subtract 1000 elements from 9 elements, like "out = vector9x1 - vector1000x1" <== that's not allowed.
mr mo

on 5 Dec 2016