Shortening if/elseif loop for value segregation
Afficher commentaires plus anciens
I'm constructing a script that involves locating the centroid of circles and adding their area to matrix that contains the cumulative area of cirlces in 50 pixel intervals (x-direction).
The if loop that I have written works fine but is incredibly long and not easily altered without going through each line. I know that there's a more efficient and easily altered method of doing what I want. Could someone please help me?
Please note that cumulativeData(i,5) is the x-coordinate of the circles centroid and cumulativeData(i,2) is the area of circles.
nRows=size(cumulativeData,1);
cumulativeArea=zeros(25,1);
for i=1:nRows
if (0<cumulativeData(i,5))&&(cumulativeData(i,5)<50)
cumulativeArea(1,1)=cumulativeArea(1,1)+cumulativeData(i,2);
elseif (50<cumulativeData(i,5))&&(cumulativeData(i,5)<100)
cumulativeArea(2,1)=cumulativeArea(2,1)+cumulativeData(i,2);
elseif (100<cumulativeData(i,5))&&(cumulativeData(i,5)<150)
cumulativeArea(3,1)=cumulativeArea(3,1)+cumulativeData(i,2);
elseif (150<cumulativeData(i,5))&&(cumulativeData(i,5)<200)
cumulativeArea(4,1)=cumulativeArea(4,1)+cumulativeData(i,2);
elseif (200<cumulativeData(i,5))&&(cumulativeData(i,5)<250)
cumulativeArea(5,1)=cumulativeArea(5,1)+cumulativeData(i,2);
etc...
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!