简体   繁体   中英

Find “external” elements bigger than a threshold value in a 3D matrix

I was wondering if someone could help me come up with a code for a 3D image I'm working on wright now.

I've got a simple 3D matrix:

A(:,:,1) =

 0 7 4
 0 32 9
 4 3 1

A(:,:,2) =

 6 0 4
 3 4 6
 2 3 11

A(:,:,3) =

12 2 4
10 20 6
14 3 2

I would like to find those values that are bigger than a threshold value (for example biger than 7). However I only want those that are exterior elements, that is, not "central" elements (the 32 on the first layer of the matrix shouldn't be marked as a maximum)

(I'm working with a bigger matrix but I guess that once I'm able to do this for the small 3D matrix from above, it won't be difficult to do it for larger ones).

Thank you a lot

Try this:

A = randn(4,4,4); % data. Arbitrary size
th = 1; % threshold

ind = find(A>th);
[x y z] = ind2sub(size(A), ind);
ext = find((x==1)|(x==size(A,1))|(y==1)|(y==size(A,2))|(z==1)|(z==size(A,3)));

ind_solution = ind(ext); % linear index of desired values
solution = A(ind_solution) % desired values

I'm guessing you could extract vectors from those matrices... so it's a matter of getting the external vectors and looping trough their elements.

I think this link will help you extract a vector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM