ERROR with type off data

1 Ansicht (letzte 30 Tage)
Nu9
Nu9 am 10 Okt. 2011
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

Antworten (3)

Fangjun Jiang
Fangjun Jiang am 10 Okt. 2011
try
W(iter)=wmax-((wmax-wmin)/single(itmax))*iter
  1 Kommentar
Nu9
Nu9 am 10 Okt. 2011
now it shows this error
??? Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles.

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 10 Okt. 2011
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 Kommentar
Nu9
Nu9 am 10 Okt. 2011
thanks for the help

Melden Sie sich an, um zu kommentieren.


Laura Proctor
Laura Proctor am 10 Okt. 2011
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 Kommentar
Nu9
Nu9 am 10 Okt. 2011
thanks it worked just as the tip from andrei bobrov

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by