In: Advanced Math
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and returns only the odd index entries. Do this by first setting the even entries to 0, and then removing the 0 entries by using a logical array. The first line of your code should read
function p = ReturnOddEntries(p)
For example, if you run in the command window p = ReturnOddEntries([1.2 7.1 8.4 -42 100.1 7 -2 4 6]), then you should get
p = [1.2 8.4 100.1 -2 6]
%%Matlab function for removing odd entries
clear all
close all
%given arrey
x=[1.2 7.1 8.4 -42 100.1 7 -2 4 6];
fprintf('Given arrey is \n')
disp(x)
%after removing odd entries
p = ReturnOddEntries(x);
fprintf('after removing odd entries the arrey is \n')
disp(p)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function p = ReturnOddEntries(x)
len=length(x);
for i=1:len
if mod(i,2)==0
p(i)=0;
else
p(i)=x(i);
end
end
p(p==0)=[];
end
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%