Prev: Range of parameters used in OFDM
Next: Subscript indices must either be real positive integers or logicals error in simple array program
From: Joseph Reierson on 25 May 2010 11:04 dofour <dofour(a)hotmail.com> wrote in message <32951087.1204455756349.JavaMail.jakarta(a)nitrogen.mathforum.org>... > Hi, > > How can I tell matlab to stop the program if calculated number is not a integer. > > Many thanks I was able to do it with a double unit conversion so to speak, and used a conditional to compare values. You might try something to this effect, and of course end the loop as needed. z = [3.001 3.00 3 3.45 3.5 3.89 4.01 4]; w = double(int8(z)); for k = 1:length(z) if (z(k) == w(k)) x(k) = 1; else x(k) = 0; end end display(z) display(w) display(x) results are: z = 3.0010 3.0000 3.0000 3.4500 3.5000 3.8900 4.0100 4.0000 w = 3 3 3 3 4 4 4 4 x = 0 1 1 0 0 0 0 1 |