Could anyone help me to solve the error
1 次查看(过去 30 天)
显示 更早的评论
E = [2 3 0 0 5;
5 6 0 0 4;
1 9 0 0 3]
P = [1 5 0 0 6;
4 3 0 0 2;
7 8 0 0 9]
U=sort(E,'descend')
V=sort(P)
for k=1:3
throughput =(Bmax.*log2(1+((V(k).*U(k))./(noise+(sum(U,1,k-1).*V(k))))))
end
If i run the code i am getting Error using sum
Trailing string input must be 'double', 'native', 'default', 'omitnan' or 'includenan'.
Error in (line 15) throughput =(Bmax.*log2(1+((V(k).*U(k))./(noise+(sum(U,1,k-1).*V(k)))))).
Could anyone help me to solve the error
0 个评论
回答(1 个)
Jan
2018-1-15
编辑:Jan
2018-1-15
The error message gets clear, if you read the documentation:
doc sum
Please do this before you ask in the forum if you have a problem with a command.
What do you want to calculate by sum(U,1,k-1)? While the 2st input is the array to sum up, the 2nd is the dimension to operate on. But what is the purpose of "k-1"? Because you did not explain (e.g. in a comment) what the code should do, I cannot suggest a solution.
By the way: The variable "throughput" is overwritten in each iteration. Maybe you want:
throughput(k) = ...
4 个评论
Jan
2018-1-16
编辑:Jan
2018-1-16
@Prabha Kumaresan: I guess you mean:
sum(1:k-1)
or
sum(U(1:k-1))
Sorry, Prabha, there is not way to avoid reading the documentation. If you have a problem with a command, start here:
doc sum
Trying sum(U,1,k-1) to solve "U is going to take the lower limit 1 to upper limit k-1" is pure guessing. This will not work for a computer language. Come on, this is your 163.th question in this forum.
Walter Roberson
2018-1-16
The original equation has seemingly been posted several times now. It does not select a subset of U to add: in the original equation i appears to be a free variable so the complete i is being selected each iteration of the summation, so the summation would collapse into a multiplication by the number of items being summed. It is, of course, possible that the posted equation has been incorrect multiple times.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!