Culling of Vector
Given inputs of (1) a row vector and (2) a digit, identify the elements of that vector that contain the digit, remove them, and return the remaining elements.
digitRemove([1 2 5 13 55 23 15],5) --> [1 2 13 23]
digitRemove([3 24 7 9 18 55 67 71],7) --> [3 24 9 18 55]
digitRemove([1 2 5 13 55 23 15],5) --> [1 2 13 23]
digitRemove([3 24 7 9 18 55 67 71],7) --> [3 24 9 18 55]
MATLAB CODE:
clc
clear all
close all
x=input('Enter the array:');
k=input('Enter the number:');
RX=[];
for i=1:length(x)
m=x(i);
c=0;
while(m>0)
b=rem(m,10);
if(b==k)
c=c+1;
end
m=(m-b)/10;
end
if(c==0)
RX=[RX x(i)];
end
end
disp(RX);
Explanation:
Output:
Using Function:
function RX= digitRemove(x,k)
RX=[];
for i=1:length(x)
m=x(i);
c=0;
while(m>0)
b=rem(m,10);
if(b==k)
c=c+1;
end
m=(m-b)/10;
end
if(c==0)
RX=[RX x(i)];
end
end
end
No comments