How to count number of Elements in a coloumn matrix of 10 entries.
2 views (last 30 days)
Show older comments
Dear I am working on KNN method where a is a resultant classified matrix lets a=[1:1:1:3:1:1:10:3:1:1]. Now I want to write a program that calculates the accuracy of how many 1(ones) are in a. If you do not know KNN method then take it as a simple problem of finding the percentage or weight-age of 1(one) in whole column matrix a. Please any one help me.
Regards.
0 Comments
Accepted Answer
dpb
on 5 Jun 2014
Edited: dpb
on 5 Jun 2014
IIUC, that would simply be
sum(a==1)/length(a);
I'm presuming you meant semicolons in place of the colons in your sample a; for it one gets
>> a=[1 1 1 3 1 1 10 31 1].';
>> sum(a==1)/length(a)
ans =
0.6667
>>
BTW, your a has only 9 entries as given...hence the 2/3-rds value of 6/9 instead of an even tenth.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!