how to count number of elements greater than ?
297 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Geoff Hayes
on 4 Apr 2015
Edited: Geoff Hayes
on 4 Apr 2015
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 Comments
Nicholas Prebble
on 30 Nov 2019
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
on 1 Dec 2019
Nicholas, attach your m-file and image file so we can reproduce it and fix it. Preferably in a new thread.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!