This line is the issue:
b(:,j) = a(x);
If x
contains some zeros (i.e. outliers were found), the output of a(x)
is smaller than your original a
. Therefore you are trying to replace b(:,j)
- 126 values - with a(x)
- less than 126 values, hence dimension mismatch.
You could just replace any outliers with NaN
:
b(dec_mad,j)=NaN;
Or use a cell array which would allow your individual output columns to be different sizes.
out{j} = a(x);
Incidentally, it's best not to use j
for loops, it's a MATLAB built-in for complex numbers.