Data Storing

A vector x’ bas been obtained from measurements. Suppose we want to consider any data value in the -range -0.1 < x < 0.1 as being erroneous. We want to remove all such elements 3IW replace them ‘with zeros at the end of the array. Develop two ways of doing .this. An eumple is given in the following table.


• Solution
The following script file uses a for loop with conditional statements. Note how the null
array [l is used.
x = [1.92,0.05,-2.43,-0.02,0.09,0.85,-0.06];
‘:/ • []; z • [J;
for k • 1:1ength(x)
if abs~x(k)) >- OIl
‘:/• [,:/,x'(IkI)
z • [z,x(k)l;
xnew. [,:/,zeros(size(z))J
The next script file uses the find function.
x = [1.92,O.05,-2.43,-0.02,O.09,O.85,-0.06J;
‘:/ = x(find(abs(x) >= 0.1));
z = zeros(size(find(abs(x)<O.l)));
xnew •• [,:/,zJ

Share This