function x = binary2decimal( b , xl , xu ,q )
syms p
s=symsum(((2^p)*b(p)),p ,1 ,(q-1))
x = (xl+((xu-xl)*(s/((2^q)-1))))
error
Invalid indexing or function definition. When defining a function, ensure that the body of the function is a SYM object.
When indexing, the input must be numeric, logical or ':'.
Error in binary2decimal (line 3)
s=symsum(((2^p)*b(p)),p ,1 ,(q-1))

 채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 6일

0 개 추천

You cannot use a symbolic variable as an index into an array, not even within a symsum() or symprod() .
Instead you need to create all of the elements as a vector, and sum() them together.
There is no good reason to use the symbolic toolbox here at all.
p = 1 : q-1;
s = sum( 2.^p .* b(p) );
This is equivalent to what you tried to code. It deliberately has the same bug you had. (Hint: why does it only produce even results ?)

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by