MATLAB: How to seperate even or odd elements and make row vectors from a matrix

functionif statementrem

Hi everyone I am going to attempt that question : Write a function called separate_by_two that takes a matrix A of positive integers as an input and returns two row vectors. The first one contains all the even elements of A and nothing else, while the second contains all the odd elements of A and nothing else, both arranged according to column-­‐major order of A. You are not allowed to use for-­‐loops or while-­‐loops.
I am using that code
function[odd_ones even_ones]=separate_by_two(A)
odd_fin = rem(A,2) ~= 0;
number_odd = A(odd_fin);
number_even = A(~odd_fin);
odd_ones=number_odd';
even_ones=number_even';
end
but getting that error
Problem 7 (separate_by_two):
Feedback: Your program made an error for argument(s) 1
What correction i needed in my code? thanks in advance for assistance..

Best Answer

The only error I see is that your returned values are in reversed order. According to the statement of the problem you should have
function[even_ones, odd_ones] = separate_by_two(A)