필터 지우기
필터 지우기

how to count number of elements greater than ?

조회 수: 209 (최근 30일)
menna gamal
menna gamal 2015년 4월 4일
댓글: Image Analyst 2019년 12월 1일
i'am new in matlab i want to the ways to count the number of formfactor in this code is greater than (e.g. 0.8)then this is normal Cell for example and print the number of normal and the number(abnormal) it is between (0.31-0.5)
hold on;
S =regionprops(Label,'area','perimeter');
for i=1:num
x(i)=S(i).Area;
y(i)=S(i).Perimeter;
%Form factor=4* pi * area/ (perimeter* perimeter)
form(i)=4.*pi.*x(i)./(y(i).^2);
end
i think to make array and if statement which save the true from if statement in array , and i try to make this :
NormalCount=sum(form(i)==1 || form(i)>=0.8);
AbnormalCount=sum(form(i)<0.8);
message1 = sprintf('Number of normal cells: %d %d',NormalCount);
message2 = sprintf('Number of Abnormal cells: %d %d',AbnormalCount);
msgbox({message1,message2});
But the result from this is wrong and i don't know this in for loop or i put it put ?
thanks.

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 4월 4일
편집: Geoff Hayes 2015년 4월 4일
Menna - rather than using find just use the greater than operator to determine which elements of form are greater than 0.8 and then sum the result. Note that
form>0.8
will return an array of 0s and 1s where each zero indicates that the element in form at the index where the zero appears is not greater than 0.8, and each one indicates that the element in form at the index where the one appears is greater than 0.8.
For example, if
form = [0.1 0.9 0.83 0.33 0.22 0.44 0.99];
then
form>0.8
returns
0 1 1 0 0 0 1
as expected. Then just sum the result as
NormalCount = sum(form>0.8);
For your abnormal count, just do
AbnormalCount = sum(form>=0.31 & form<=0.5);
  댓글 수: 6
Nicholas Prebble
Nicholas Prebble 2019년 11월 30일
When I do this I recieve the error message "The logical indices contain a true value outside of the array bounds."
Error in practice (line 3)
NormalCount = sum(form>0.8);
Image Analyst
Image Analyst 2019년 12월 1일
Nicholas, attach your m-file and image file so we can reproduce it and fix it. Preferably in a new thread.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by