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

2 ビュー (過去 30 日間)
Zishan
Zishan 2014 年 6 月 5 日
コメント済み: Zishan 2014 年 6 月 5 日
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