how to overcome undefined function sum.
이전 댓글 표시
throughput_E =@(t)Bmax*log2(1+p_fix(t)*gamma(t)/sum(p_fix(q,1,t-1).*gamma(t)));
overall_throughput_E = sum(sum(throughput_E));
If i run the code i am getting Undefined function 'sum' for input arguments of type 'function_handle'.
Error in overall_throughput_E = sum(sum(throughput_E));
댓글 수: 4
KSSV
2017년 12월 29일
define p_fix as a anonymous function and try.
Prabha Kumaresan
2017년 12월 29일
편집: Matt J
2017년 12월 29일
KSSV
2017년 12월 29일
:( what is p_fix.....show us this function.
Prabha Kumaresan
2017년 12월 29일
답변 (1개)
You need to give some sort of input to throughput_E in this line
sum(sum( throughput_E( t_input) ));
댓글 수: 3
John D'Errico
2017년 12월 29일
To amplify on what Matt said, and explain why there was a problem...
throughput_E is a function handle. It seems like it makes sense that you can sum the function, simply by putting it inside sum. But MATLAB does not understand your goal here. MATLAB is a very literal tool. The function sum looks at what you passed in. Sum recognizes only numeric inputs as candidates to be summable. It looks at throughput_E, and sees that it is NOT a number or vector or array of numbers. So sum just gives up and throws an error.
If you change things, so that throughput_E has an input as did Matt, then the result is now numeric. MATLAB evaluates the function at t_input, then passes the result to sum. All is good now.
Sometimes you really don't immediately have the input to throughput_E at the moment, but you want to define a new function that will take any input and sum the result, after going through throughput_E? Just create a NEW function, as I do here:
sum_of_throughput_E = @(inp) sum(sum(throughput_E(inp)));
So now you can use this new function as the summed result.
Prabha Kumaresan
2017년 12월 29일
편집: Walter Roberson
2017년 12월 29일
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!