Maximum perimeter of cells with special value in dispersal configuration

1 vue (au cours des 30 derniers jours)
fatema saba
fatema saba le 23 Jan 2015
Modifié(e) : fatema saba le 23 Jan 2015
Hello The following script calculate perimeter of maximum dispersal configuration of value 1 in matrix x.
"minconfig" is perimeter that is calculated by adding sides of cells(elements) with value 1 when these cells are adjacent to cells(elements) with value 0 or are located in boundary.
for example when matrix x is 3D matrix (size x:(m=4,n=5,k=2))and number of cells with value 1 in dimension 1 is 11 and in dimension 2 is 10, I get 2 results as perimeter by running this script. How can get sum of these results.
Thank you
i
function mincompact
load ('pakon5')
[m n k]=size(x)
for K=1:k
cellsone_x=nnz(x(:,:,K))
cells=m*n
fx=fix(cells/2)
rm=rem(cells,2)
if rm>0
qt=fx+1
elseif rm==0
qt=fx
end
if cellsone_x<=qt
minconfig(K)=(4*cellsone_x)
elseif cellsone_x>qt
extra=cellsone_x-qt
fxm=fix(m/2)
fxn=fix(n/2)
rmm=rem(m,2)
rmn=rem(n,2)
if rmm>0
qttm1=fxm
qttm2=fxm+1
elseif rmm==0
qttm1=fxm
qttm2=fxm-1
end
qttm=qttm1+qttm2
if rmn>0
qttn1=fxn
qttn2=fxn+1
elseif rmn==0
qttn1=fxn
qttn2=fxn-1
end
qttn=qttn1+qttn2
qtt=(qttm+qttn)-1
qtt_minus2=qtt-2
if extra<=qtt
minconfig(K)=((4*qt)-(qtt_minus2*2))
elseif extra>qtt
minus=extra-qtt
minconfig(K)=((4*qt)-((qtt_minus2*2)+(minus*4)))
end
end
end
end

Réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by