I have a matrix `A` of size 13472x1537. This matrix contains values smaller than 1. In my case I seek for a solution to satisfy the following condition:
If a column contains a value smaller than 1, replace all other values in the same column with `NaN`.

I was able to implement a code that could replace these values (smaller than 1) with the previous value (or any value). However, I am looking for a solution that changes every value in the column to `NaN` no matter whether later (or previous) values are greater than 1.

I have `i=1537`; `t=13472`

```
for i = 1:size(A,2) 
    I = A(1,i);
    for t= 2:size(A,1)
        if A(t,i) <= 1
           A(t,i) = I;
        else
        I = A(t,i);
        end
    end
end

```
['https://Stackoverflow.com/questions/47113078', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7758301/']
A version, which gets rid of the loop would look like this:

```
A = randn(5)+2; % Random example
[row,col] = find(A<1);
A(:,col) = NaN;

```

If you would want to keep the values smaller than 1 in the matrix a solution could look something like this:

```
A = randn(5)+2; % Random example
[row,col,ind] = find(A<1);
b = A(ind)
A(:,col) = NaN;
A(ind) = b;

```
That would be like the following

```
for i = 1:size(A,2) 
    if ~isempty(find(A(:,i) <= 1))
        A(:,i)=nan(size(A,1),1);
    end
end

```