How to count number of Elements in a coloumn matrix of 10 entries.

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

采纳的回答

dpb
dpb 2014-6-5
编辑:dpb 2014-6-5
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.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by