how to count number of elements greater than ?

209 次查看(过去 30 天)
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