Calculating the strangeness using k constant

1 次查看(过去 30 天)
A B
_______ __
0.57446 C1
0.61644 C2
0.93808 C1
2.1817 C2
2.9883 C1
3.1654 C2
if I want to do this calculations such divide all the sums of C1 by all the sums of C2 how do I go about it. using a constant suck as K to determine the number to sum.
for instance if k = 2
strangeness = sum of the smallest 2 numbers of c1/ sum of the smallest 2 numbers of c2
if K = 3
strangeness = sum of the smallest 3 numbers of c1/sum of the smallest 3 numbers of C2
Thanks in advance
Jonathan

回答(1 个)

Stephen23
Stephen23 2019-4-10
>> a = [0.6164;3.1654;0.5745;2.9883;0.9381;2.1817];
>> c1 = sort(a(1:2:end));
>> c2 = sort(a(2:2:end));
>> K = 2;
>> sum(c1(1:K))/sum(c2(1:K))
ans = 0.23035
  2 个评论
Stephen23
Stephen23 2019-4-10
Jonathan Etumusei's "Answer" moved here:
Hi Stephen thanks for your swift response
>> c1 = sort(totalY11(1:2:end));
I am getting the error
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not supported. Use a row subscript and a variable subscript.
How do I go about it
Thanks in advance
sorry got it sorted was because the table is in the form
A B
_______ __
0.57446 C1
0.61644 C2
0.93808 C1
2.1817 C2
2.9883 C1
3.1654 C2

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by