"Sagnik Basu Choudhuri" <sindhurakshak22@gmail.com> wrote in message <mja6nu$9p7$1@newscl01ah.mathworks.com>...
> Hello all,
>
> Need your quick help for an assignment.
>
> The question is as follows:
>
> Write a function division 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.
>
> Use of While and For Loops is prohibited.
>
>
> A quick reply would be deeply appreciated.
function splitMatrix(matX )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
evenMatrix = (~mod(matX,2)).*matX(:,:);
oddMatrix = (mod(matX,2)).*matX(:,:);
evenMatrix = evenMatrix(evenMatrix~=0);
evenMatrix = evenMatrix';
oddMatrix = oddMatrix(oddMatrix~=0);
oddMatrix = oddMatrix';
disp(evenMatrix);
disp(oddMatrix);
end
> Hello all,
>
> Need your quick help for an assignment.
>
> The question is as follows:
>
> Write a function division 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.
>
> Use of While and For Loops is prohibited.
>
>
> A quick reply would be deeply appreciated.
function splitMatrix(matX )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
evenMatrix = (~mod(matX,2)).*matX(:,:);
oddMatrix = (mod(matX,2)).*matX(:,:);
evenMatrix = evenMatrix(evenMatrix~=0);
evenMatrix = evenMatrix';
oddMatrix = oddMatrix(oddMatrix~=0);
oddMatrix = oddMatrix';
disp(evenMatrix);
disp(oddMatrix);
end