how to find the lowest pixel in a 3d matrix?

hello, I have 3D matrix with ones and zeroes. I need to know the index of the lowest and highest pixel with 1 value. lets say the Z axis is height, than I need to know the min/max height of the pixels with the value 1.
thank you!

 Accepted Answer

Assuming your 3D array is A
map=any(reshape(A,[],size(A,3)),1);
minheight =find(map,1);
maxheight=find(map,1,'last');

More Answers (1)

A = rand(15,5,5) < .3; % your data
s = size(A);
B = reshape(A,s(1),[]);
[ii jj] = find(B);
maxl = ii == max(ii);
[i1 j1] = ind2sub(s(2:3),jj(maxl));
maxidx = [ii(maxl),i1,j1];
minl = ii == min(ii);
[i2 j2] = ind2sub(s(2:3),jj(minl));
minidx = [ii(minl),i2,j2]

Categories

Tags

Asked:

on 4 Jun 2013

Community Treasure Hunt

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

Start Hunting!