Could anyone help me to solve the error

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

Answers (1)

Jan
Jan on 15 Jan 2018
Edited: Jan on 15 Jan 2018
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 Comments

with respect to sum(U,1,k-1) U is going to take the lower limit 1 to upper limit k-1.
Stephen23
Stephen23 on 16 Jan 2018
Edited: Jan on 16 Jan 2018
@Prabha Kumaresan: how does this relate in any way to the sum function? Did you read its documentation yet? Inventing syntaxes is a waste of your time, you would be much better off reading the documentation to know how MATLAB works.
@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.
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.

Sign in to comment.

Tags

Asked:

on 15 Jan 2018

Commented:

on 16 Jan 2018

Community Treasure Hunt

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

Start Hunting!