On 10/26/2012 10:22 AM, Hamad Ali wrote:
> "Rubi " <phreakadelik@hotmail.com> wrote in message
> <glikor$epo$1@fred.mathworks.com>...
>> Hi and thanks for any idea or code !
>>
>> Im new at matlab I have an .m file UY=[0.513671875
>> 0.620666504
>> 115.847168
>> 256.2485046
>> 230.8596191
>> ....]
>>
>> And i have to separate in a new file the even numbers and odd numbers
>> is that posible having decimals? i searched and i found this code
>> if mod(x,2) == 0
>> %number is even
>> else
>> %number is odd
>> end
...
> I am so sorry cause the thread is out of date but I put my post here as
> it might be useful for some body else
>
> I think for loop can give you a proper answer to your question and
> therefore try this small code
>
...
> for k = 1:length(x)
> y = x(mod(x,2)~=0);
> z = x(mod(x,2)==0);
> end
>
> disp('Even numbers in x are:' )
> disp(z)
> disp('Odd numbers in x are:' )
> disp(y)
...
Well, this doesn't address the OP's problem of having floating point
values at all and one doesn't need any loops in Matlab...and, in fact,
your code above works if you simply remove the for and end statements
(and as written does the same thing every time through for the entire
array).
For the OP's question there really isn't an answer other than would have
to round somehow depending on what is/would be wanted.
--
y=x(mod(x,
> "Rubi " <phreakadelik@hotmail.com> wrote in message
> <glikor$epo$1@fred.mathworks.com>...
>> Hi and thanks for any idea or code !
>>
>> Im new at matlab I have an .m file UY=[0.513671875
>> 0.620666504
>> 115.847168
>> 256.2485046
>> 230.8596191
>> ....]
>>
>> And i have to separate in a new file the even numbers and odd numbers
>> is that posible having decimals? i searched and i found this code
>> if mod(x,2) == 0
>> %number is even
>> else
>> %number is odd
>> end
...
> I am so sorry cause the thread is out of date but I put my post here as
> it might be useful for some body else
>
> I think for loop can give you a proper answer to your question and
> therefore try this small code
>
...
> for k = 1:length(x)
> y = x(mod(x,2)~=0);
> z = x(mod(x,2)==0);
> end
>
> disp('Even numbers in x are:' )
> disp(z)
> disp('Odd numbers in x are:' )
> disp(y)
...
Well, this doesn't address the OP's problem of having floating point
values at all and one doesn't need any loops in Matlab...and, in fact,
your code above works if you simply remove the for and end statements
(and as written does the same thing every time through for the entire
array).
For the OP's question there really isn't an answer other than would have
to round somehow depending on what is/would be wanted.
--
y=x(mod(x,