필터 지우기
필터 지우기

ERROR with type off data

조회 수: 1 (최근 30일)
Nu9
Nu9 2011년 10월 10일
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일
try
W(iter)=wmax-((wmax-wmin)/single(itmax))*iter
  댓글 수: 1
Nu9
Nu9 2011년 10월 10일
now it shows this error
??? Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles.

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2011년 10월 10일
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);
  댓글 수: 1
Nu9
Nu9 2011년 10월 10일
thanks for the help

댓글을 달려면 로그인하십시오.


Laura Proctor
Laura Proctor 2011년 10월 10일
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
Nu9
Nu9 2011년 10월 10일
thanks it worked just as the tip from andrei bobrov

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by