ERROR with type off data

hi, when i run my script it show this error
Error using ==> rdivide
Integers can only be combined with integers of the same class, or scalar doubles.
in this line
for iter=1:itmax
W(iter)=wmax-((wmax-wmin)/itmax)*iter;
wmax and wmin are saved as 'single' and itmax as 'uint8'.W is defined as '<1x50 single>' in workspace and and iter is just a value in workspace

回答(3 个)

Fangjun Jiang
Fangjun Jiang 2011-10-10

0 个投票

try
W(iter)=wmax-((wmax-wmin)/single(itmax))*iter

1 个评论

now it shows this error
??? Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles.

请先登录,再进行评论。

k = single(itmax);
for iter=1:k
W(iter)=wmax-((wmax-wmin)/k)*iter;
...
end
or
W(iter)=wmax-((wmax-wmin)/single(itmax))*single(iter);
Because you are creating the variable iter from the variable itmax, it will also be uint8, so you will need to cast it as a single as well:
W(iter) = wmax -( (wmax-wmin)/single(itmax) ) * single(iter);

1 个评论

thanks it worked just as the tip from andrei bobrov

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

提问:

Nu9
2011-10-10

Community Treasure Hunt

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

Start Hunting!

Translated by